Esempio 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);
        }
Esempio 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();
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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;
        }
Esempio 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();
        }
Esempio 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);
        }
        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;
        }
Esempio n. 9
0
        public Type ConvertNotNull(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();

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

            return elementType.MakeArrayType();
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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();
        }
Esempio n. 14
0
        public Type ConvertNotNull(TypeUsage type)
        {
            FacetInfo facets = new FacetInfo();

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

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

            return(elementType.MakeArrayType());
        }