Exemplo n.º 1
0
        public bool TryConvertEdmType(PrimitiveType primitiveType, FacetInfo facets, out Type result)
        {
            result = null;

            if (string.Equals("binary", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase) ||
                string.Equals("image", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Data.Binary);
                return(true);
            }

            if (string.Equals("rowversion", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase) ||
                string.Equals("timestamp", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Data.Timestamp);
                return(true);
            }

            if (string.Equals("geometry", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Spatial.DbGeometry);
                return(true);
            }

            if (string.Equals("geography", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Spatial.DbGeography);
                return(true);
            }


            return(false);
        }
Exemplo n.º 2
0
 public EntityPropertyInfo(
     string name,
     Type type,
     FacetInfo facets,
     List<IndexInfo> indexes)
 {
     this.name = name;
     this.type = type;
     this.facets = facets;
     this.indexes = indexes.ToList().AsReadOnly();
 }
Exemplo n.º 3
0
        private Type CreateRowType(RowType rowType, FacetInfo facets)
        {
            Dictionary <string, Type> members = new Dictionary <string, Type>();

            foreach (EdmMember member in rowType.Members)
            {
                members.Add(member.GetColumnName(), this.Convert(member.TypeUsage));
            }

            Type result = DataRowFactory.Create(members);

            return(result);
        }
Exemplo n.º 4
0
        public FacetInfo GetTypeFacets(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();
            Facet     facet  = null;

            if (type.Facets.TryGetValue("Nullable", false, out facet))
            {
                facets.Nullable = (bool)facet.Value == true;
            }

            if (type.Facets.TryGetValue("FixedLength", false, out facet))
            {
                if (!facet.IsUnbounded && facet.Value != null)
                {
                    facets.FixedLength = (bool)facet.Value == true;
                }
            }

            if (type.Facets.TryGetValue("StoreGeneratedPattern", false, out facet))
            {
                switch ((StoreGeneratedPattern)facet.Value)
                {
                case StoreGeneratedPattern.Computed:
                    facets.Computed = true;
                    break;

                case StoreGeneratedPattern.Identity:
                    facets.Identity = true;
                    break;
                }
            }

            if (type.Facets.TryGetValue("MaxLength", false, out facet))
            {
                if (facet.IsUnbounded)
                {
                    facets.LimitedLength = false;
                }
                else if (facet.Value != null)
                {
                    facets.MaxLength     = (int)facet.Value;
                    facets.LimitedLength = true;
                }
            }

            return(facets);
        }
Exemplo n.º 5
0
        public FacetInfo GetTypeFacets(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();
            Facet facet = null;
            
            if (type.Facets.TryGetValue("Nullable", false, out facet))
            {
                facets.Nullable = (bool)facet.Value == true;
            }

            if (type.Facets.TryGetValue("FixedLength", false, out facet))
            {
                if (!facet.IsUnbounded && facet.Value != null)
                {
                    facets.FixedLength = (bool)facet.Value == true;
                }
            }

            if (type.Facets.TryGetValue("StoreGeneratedPattern", false, out facet))
            {
                switch ((StoreGeneratedPattern)facet.Value)
                {
                    case StoreGeneratedPattern.Computed:
                        facets.Computed = true;
                        break;
                    case StoreGeneratedPattern.Identity:
                        facets.Identity = true;
                        break;
                }
            }

            if (type.Facets.TryGetValue("MaxLength", false, out facet))
            {
                if (facet.IsUnbounded)
                {
                    facets.LimitedLength = false;
                }
                else if (facet.Value != null)
                {
                    facets.MaxLength = (int)facet.Value;
                    facets.LimitedLength = true;
                }
            }

            return facets;
        }
Exemplo n.º 6
0
        private Type ConvertWithFacets(TypeUsage type, FacetInfo facets)
        {
            if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType)
            {
                return(this.CreatePrimitiveType(type.EdmType as PrimitiveType, facets));
            }
            else if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.RowType)
            {
                return(this.CreateRowType(type.EdmType as RowType, facets));
            }
            else if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
            {
                return(this.CreateCollectionType(type.EdmType as CollectionType, facets));
            }

            throw new NotSupportedException();
        }
Exemplo n.º 7
0
        private Type CreatePrimitiveType(PrimitiveType primitiveType, FacetInfo facets)
        {
            Type result = null;

            if (this.converter.TryConvertEdmType(primitiveType, facets, out result))
            {
                return(result);
            }

            result = primitiveType.ClrEquivalentType;

            if (facets.Nullable && result.IsValueType)
            {
                result = typeof(Nullable <>).MakeGenericType(result);
            }

            return(result);
        }
Exemplo n.º 8
0
        public bool TryConvertEdmType(PrimitiveType primitiveType, FacetInfo facets, out Type result)
        {
            result = null;

            if (string.Equals("binary", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Data.Binary);
                return true;
            }

            if (string.Equals("rowversion", primitiveType.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                result = typeof(NMemory.Data.Timestamp);
                return true;
            }

            return false;
        }
Exemplo n.º 9
0
        public Type ConvertNotNull(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();

            return this.ConvertWithFacets(type, facets);
        }
Exemplo n.º 10
0
        private Type CreateCollectionType(CollectionType collectionType, FacetInfo facets)
        {
            Type elementType = this.ConvertWithFacets(collectionType.TypeUsage, facets);

            return elementType.MakeArrayType();
        }
Exemplo n.º 11
0
        private Type CreateRowType(RowType rowType, FacetInfo facets)
        {
            Dictionary<string, Type> members = new Dictionary<string, Type>();

            foreach (EdmMember member in rowType.Members)
            {
                members.Add(member.GetColumnName(), this.Convert(member.TypeUsage));
            }

            Type result = DataRowFactory.Create(members);

            return result;
        }
Exemplo n.º 12
0
        private Type CreatePrimitiveType(PrimitiveType primitiveType, FacetInfo facets)
        {
            Type result = null;
            if (this.converter.TryConvertEdmType(primitiveType, facets, out result))
            {
                return result;
            }
            
            result = primitiveType.ClrEquivalentType;

            if (facets.Nullable && result.IsValueType)
            {
                result = typeof(Nullable<>).MakeGenericType(result);
            }

            return result;
        }
Exemplo n.º 13
0
        private Type ConvertWithFacets(TypeUsage type, FacetInfo facets)
        {
            if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType)
            {
                return this.CreatePrimitiveType(type.EdmType as PrimitiveType, facets);
            }
            else if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.RowType)
            {
                return this.CreateRowType(type.EdmType as RowType, facets);
            }
            else if (type.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
            {
                return this.CreateCollectionType(type.EdmType as CollectionType, facets);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 14
0
        public Type ConvertNotNull(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();

            return(this.ConvertWithFacets(type, facets));
        }
Exemplo n.º 15
0
        public Type Convert(TypeUsage type)
        {
            FacetInfo facets = this.GetTypeFacets(type);

            return(this.ConvertWithFacets(type, facets));
        }
Exemplo n.º 16
0
        private Type CreateCollectionType(CollectionType collectionType, FacetInfo facets)
        {
            Type elementType = this.ConvertWithFacets(collectionType.TypeUsage, facets);

            return(elementType.MakeArrayType());
        }