示例#1
0
        private bool TryGetEdmDataType(Type clrType, out PrimitiveDataType edmPrimitiveDataType)
        {
            if (this.clrTypeToPrimitiveDataTypeMap.TryGetValue(clrType, out edmPrimitiveDataType))
            {
                return(true);
            }

            // TODO: should query type library be aware of Edm version? Use latest for now.
            foreach (var t in EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest))
            {
                var primitiveDataType = t;
                var spatialDataType   = primitiveDataType as SpatialDataType;
                if (spatialDataType != null)
                {
                    primitiveDataType = this.TryResolveConceptualSpatialDataType(spatialDataType);
                    if (primitiveDataType == null)
                    {
                        continue;
                    }
                }

                if (this.DoesClrTypeMatch(primitiveDataType, clrType))
                {
                    this.clrTypeToPrimitiveDataTypeMap[clrType] = primitiveDataType;
                    edmPrimitiveDataType = primitiveDataType;
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Initializes the converter
        /// </summary>
        internal void Initialize()
        {
            if (!this.initialized)
            {
                ExceptionUtilities.CheckAllRequiredDependencies(this);
                this.initialized = true;

                var types = EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest).ToList();

                foreach (PrimitiveDataType type in types)
                {
                    string edmTypeName = EdmDataTypes.GetEdmFullName(type);

                    Type clrType;
                    var  spatialType = type as SpatialDataType;
                    if (spatialType != null)
                    {
                        clrType = this.SpatialResolver.GetClrType(spatialType);
                    }
                    else
                    {
                        clrType = type.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);
                    }

                    ExceptionUtilities.CheckObjectNotNull(clrType, "Could not determine clr type for edm data type: '{0}", edmTypeName);

                    this.clrToEdm[clrType]         = type;
                    this.edmNameToClr[edmTypeName] = clrType;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Gets an Edm <see cref="PrimitiveDataType"/> that represents the underlying type of the enum.
        /// </summary>
        /// <returns>The <see cref="PrimitiveDataType"/> corresponding to the underlying type of the enum.</returns>
        public PrimitiveDataType GetUnderlyingTypeInEdm()
        {
            if (this.cachedUnderlyingTypeInEdm == null)
            {
                PrimitiveDataType underlyingTypeInEdm;

                if (this.Definition.UnderlyingType == null)
                {
                    underlyingTypeInEdm = EdmDataTypes.Int32;
                }
                else
                {
                    var allIntegerEdmTypes = EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest).OfType <IntegerDataType>();
                    underlyingTypeInEdm = allIntegerEdmTypes.SingleOrDefault(i => i.GetFacet <PrimitiveClrTypeFacet>().Value == this.Definition.UnderlyingType);
                    ExceptionUtilities.Assert(underlyingTypeInEdm != null, "Invalid underlying type for an Enum data type");
                }

                foreach (var facet in this.Facets)
                {
                    underlyingTypeInEdm = underlyingTypeInEdm.WithFacet(facet);
                }

                this.cachedUnderlyingTypeInEdm = underlyingTypeInEdm;
            }

            return(this.cachedUnderlyingTypeInEdm);
        }
示例#4
0
        /// <summary>
        /// Class constructor.
        /// </summary>
        static EntityModelUtils()
        {
            primitiveClrToEdmTypeMap = new Dictionary <Type, PrimitiveDataType>();

            clrToPrimitiveDataTypeConverter = new ClrToPrimitiveDataTypeConverter()
            {
                SpatialResolver = new SpatialClrTypeResolver()
            };
            foreach (var t in EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest))
            {
                Type clrType = clrToPrimitiveDataTypeConverter.ToClrType(t);
                if (clrType == typeof(string) || clrType == typeof(byte[]))
                {
                    // only add the nullable variants to the map for string and byte[]
                    primitiveClrToEdmTypeMap.Add(clrType, t.Nullable());
                }
                else
                {
                    primitiveClrToEdmTypeMap.Add(clrType, t);
                    if (!TestTypeUtils.TypeAllowsNull(clrType))
                    {
                        primitiveClrToEdmTypeMap.Add(typeof(Nullable <>).MakeGenericType(clrType), t.Nullable());
                    }
                }
            }
        }
示例#5
0
        private PrimitiveDataType CompensatePrimitiveDefaultFacets(PrimitiveDataType inputDataType)
        {
            var inputBinary = inputDataType as BinaryDataType;
            var inputString = inputDataType as StringDataType;

            if (inputBinary == null && inputString == null)
            {
                return(inputDataType);
            }

            int?maxLength = null;

            if (inputDataType.HasFacet <MaxLengthFacet>())
            {
                maxLength = inputDataType.GetFacet <MaxLengthFacet>().Value;
            }

            bool isUnicode = inputDataType.GetFacetValue <IsUnicodeFacet, bool>(true);

            if (inputBinary != null)
            {
                return(EdmDataTypes.Binary(maxLength)
                       .Nullable(inputDataType.IsNullable));
            }
            else
            {
                return(EdmDataTypes.String(maxLength, isUnicode)
                       .Nullable(inputDataType.IsNullable));
            }
        }
示例#6
0
            /// <summary>
            /// Resolves the specified data type.
            /// </summary>
            /// <param name="dataType">Data type specification.</param>
            /// <returns>Resolved EDM Type.</returns>
            PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(DateTimeDataType dataType)
            {
                int?precision = null;

                TimePrecisionFacet timePrecisionFacet;

                if (dataType.TryGetFacet(out timePrecisionFacet))
                {
                    precision = timePrecisionFacet.Value;
                }

                string typeName = dataType.GetFacetValue <EdmTypeNameFacet, string>(null);
                bool   hasTimeZoneOffsetFacet = dataType.GetFacetValue <HasTimeZoneOffsetFacet, bool>(false);
                Type   clrType = dataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null);
                bool   hasDateTimeOffsetEdmTypeNameFacet = "DateTimeOffset".Equals(typeName, StringComparison.OrdinalIgnoreCase);

                if (hasTimeZoneOffsetFacet && typeName != null && !hasDateTimeOffsetEdmTypeNameFacet)
                {
                    throw new TaupoInvalidOperationException(
                              string.Format(CultureInfo.InvariantCulture, "Cannot resolve date time data type as it has 'true' value for the '{0}' which contradicts with the edm type name '{1}'", typeof(HasTimeZoneOffsetFacet).Name, typeName));
                }

                if (hasTimeZoneOffsetFacet || hasDateTimeOffsetEdmTypeNameFacet || clrType == typeof(DateTimeOffset))
                {
                    return(EdmDataTypes.DateTimeOffset(precision));
                }

                if (typeName != null && !"DateTime".Equals(typeName, StringComparison.OrdinalIgnoreCase))
                {
                    throw new TaupoInvalidOperationException(
                              string.Format(CultureInfo.InvariantCulture, "Edm type name '{0}' is invalid for date time data types.", typeName));
                }

                return(EdmDataTypes.DateTime(precision));
            }
示例#7
0
 private static void AddEpmAttributes(EntityType entityType, int count, int startIndex)
 {
     for (int i = 0; i < count; ++i)
     {
         int    ix           = startIndex + i;
         string propertyName = "Name" + ix;
         entityType.Property(propertyName, EdmDataTypes.String().Nullable());
         entityType.EntityPropertyMapping(propertyName, "custom/name" + ix, "c", "http://customuri/", true);
     }
 }
示例#8
0
        /// <summary>
        /// Parses the primitive type
        /// </summary>
        /// <param name="typeName">the name of the primitive type</param>
        /// <param name="facets">the facets attributes associated with the type</param>
        /// <returns>the primitive data type representation in the entity model schema</returns>
        protected override PrimitiveDataType ParsePrimitiveType(string typeName, IEnumerable <XAttribute> facets)
        {
            IEnumerable <string> spatialTypes =
                EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.V40)
                .OfType <SpatialDataType>()
                .Select(t => EdmDataTypes.GetEdmName(t));

            if (typeName == "Binary")
            {
                return(EdmDataTypes.Binary(
                           this.GetIntFacetValue(facets, "MaxLength")));
            }
            else if (typeName == "DateTime")
            {
                return(EdmDataTypes.DateTime(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (typeName == "DateTimeOffset")
            {
                return(EdmDataTypes.DateTimeOffset(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (typeName == "Decimal")
            {
                return(EdmDataTypes.Decimal(
                           this.GetIntFacetValue(facets, "Precision"),
                           this.GetIntFacetValue(facets, "Scale")));
            }
            else if (typeName == "String")
            {
                return(EdmDataTypes.String(
                           this.GetIntFacetValue(facets, "MaxLength"),
                           this.GetBoolFacetValue(facets, "Unicode")));
            }
            else if (typeName == "Duration")
            {
                return(EdmDataTypes.Time(this.GetIntFacetValue(facets, "Precision")));
            }
            else if (this.ConsiderSrid)
            {
                if (spatialTypes.Contains(typeName))
                {
                    SpatialDataType spatialDataType = name2EdmDataType[typeName] as SpatialDataType;
                    return(this.GetSpatialDataTypeWithSrid(spatialDataType, facets));
                }
                else
                {
                    ExceptionUtilities.Assert(name2EdmDataType.ContainsKey(typeName), "EDM type '" + typeName + "' not supported.");
                    return(name2EdmDataType[typeName]);
                }
            }
            else
            {
                ExceptionUtilities.Assert(name2EdmDataType.ContainsKey(typeName), "EDM type '" + typeName + "' not supported.");
                return(name2EdmDataType[typeName]);
            }
        }
示例#9
0
        private void AddDefaultConstants(List <QueryScalarValue> scalarValues, QueryTypeLibrary queryTypeLibrary)
        {
            var intType    = (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Int32);
            var stringType = (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.String());
            var boolType   = (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Boolean);

            scalarValues.Add(intType.CreateValue(1));
            scalarValues.Add(stringType.CreateValue("Foo"));
            scalarValues.Add(boolType.CreateValue(true));
            scalarValues.Add(boolType.CreateValue(false));
        }
        private QueryScalarType GetQueryScalarTypeFromDecimalValue(decimal value)
        {
            value = Math.Abs(value);
            var truncated           = decimal.Truncate(value);
            var integralDigitsCount = truncated.ToString(CultureInfo.InvariantCulture).Length;

            // subtract 2 for leading "0."
            var fractionalDigitsCount = Math.Max((value - truncated).ToString(CultureInfo.InvariantCulture).Length - 2, 0);

            return((QueryScalarType)this.GetDefaultQueryType(EdmDataTypes.Decimal(integralDigitsCount + fractionalDigitsCount, fractionalDigitsCount)));
        }
示例#11
0
            /// <summary>
            /// Resolves the specified data type.
            /// </summary>
            /// <param name="dataType">Data type specification.</param>
            /// <returns>Resolved EDM Type.</returns>
            PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(TimeOfDayDataType dataType)
            {
                int?precision = null;
                TimePrecisionFacet timePrecisionFacet;

                if (dataType.TryGetFacet(out timePrecisionFacet))
                {
                    precision = timePrecisionFacet.Value;
                }

                return(EdmDataTypes.Time(precision));
            }
示例#12
0
        private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType)
        {
            if (commonType.HasFacet <NumericPrecisionFacet>())
            {
                ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString());
                var commonPrecision = GetCommonPrecision(leftType, rightType);
                var commonScale     = GetCommonScale(leftType, rightType);
                commonType = EdmDataTypes.Decimal(commonPrecision, commonScale);
            }

            return(commonType);
        }
示例#13
0
            /// <summary>
            /// Resolves the specified data type.
            /// </summary>
            /// <param name="dataType">Data type specification.</param>
            /// <returns>Resolved EDM Type.</returns>
            PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(BinaryDataType dataType)
            {
                int?           maxLength = null;
                MaxLengthFacet maxLengthFacet;

                if (dataType.TryGetFacet(out maxLengthFacet))
                {
                    maxLength = maxLengthFacet.Value;
                }

                return(EdmDataTypes.Binary(maxLength));
            }
示例#14
0
        /// <summary>
        /// Build a test model shared across several tests.
        /// </summary>
        /// <returns>Returns the test model.</returns>
        internal static EntityModelSchema BuildTestModel()
        {
            // The metadata model
            EntityModelSchema model = new EntityModelSchema();

            ComplexType addressType = model.ComplexType("Address")
                                      .Property("Street", EdmDataTypes.String())
                                      .Property("Zip", EdmDataTypes.Int32);

            EntityType officeType = model.EntityType("OfficeType")
                                    .KeyProperty("Id", EdmDataTypes.Int32)
                                    .Property("Address", DataTypes.ComplexType.WithDefinition(addressType));

            EntityType cityType = model.EntityType("CityType")
                                  .KeyProperty("Id", EdmDataTypes.Int32)
                                  .Property("Name", EdmDataTypes.String())
                                  .NavigationProperty("CityHall", officeType)
                                  .NavigationProperty("DOL", officeType)
                                  .NavigationProperty("PoliceStation", officeType, true)
                                  .NamedStream("Skyline")
                                  .Property("MetroLanes", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String()));

            EntityType cityWithMapType = model.EntityType("CityWithMapType")
                                         .WithBaseType(cityType)
                                         .DefaultStream();

            EntityType cityOpenType = model.EntityType("CityOpenType")
                                      .WithBaseType(cityType)
                                      .OpenType();

            EntityType personType = model.EntityType("Person")
                                    .KeyProperty("Id", EdmDataTypes.Int32);

            personType = personType.NavigationProperty("Friend", personType);

            EntityType employeeType = model.EntityType("Employee")
                                      .WithBaseType(personType)
                                      .Property("CompanyName", EdmDataTypes.String());

            EntityType managerType = model.EntityType("Manager")
                                     .WithBaseType(employeeType)
                                     .Property("Level", EdmDataTypes.Int32);

            model.Fixup();

            // Fixed up models will have entity sets for all base entity types.
            model.EntitySet("Employee", employeeType);
            model.EntitySet("Manager", managerType);

            return(model);
        }
示例#15
0
        /// <summary>
        /// Build a test model shared across several tests.
        /// </summary>
        /// <param name="addAnnotations">true if the annotations should be added upon construction; otherwise false.</param>
        /// <returns>Returns the test model.</returns>
        public static EntityModelSchema BuildODataAnnotationTestModel(bool addAnnotations)
        {
            // The metadata model with OData-specific annotations
            // - default entity container annotation
            // - HasStream annotation on entity type
            // - MimeType annotation on primitive property
            // - MimeType annotation on service operation
            EntityModelSchema model = new EntityModelSchema().MinimumVersion(ODataVersion.V4);

            ComplexType addressType = model.ComplexType("Address")
                                      .Property("Street", EdmDataTypes.String().Nullable())
                                      .Property("Zip", EdmDataTypes.Int32);

            if (addAnnotations)
            {
                addressType.Properties.Where(p => p.Name == "Zip").Single().MimeType("text/plain");
            }

            EntityType personType = model.EntityType("PersonType")
                                    .KeyProperty("Id", EdmDataTypes.Int32)
                                    .Property("Name", EdmDataTypes.String())
                                    .Property("Address", DataTypes.ComplexType.WithDefinition(addressType))
                                    .StreamProperty("Picture")
                                    .DefaultStream();

            if (addAnnotations)
            {
                personType.Properties.Where(p => p.Name == "Name").Single().MimeType("text/plain");
            }

            model.Fixup();

            // set the default container
            EntityContainer container = model.EntityContainers.Single();

            model.EntitySet("People", personType);

            // NOTE: Function import parameters and return types must be nullable as per current CSDL spec
            FunctionImport serviceOp = container.FunctionImport("ServiceOperation1")
                                       .Parameter("a", EdmDataTypes.Int32.Nullable())
                                       .Parameter("b", EdmDataTypes.String().Nullable())
                                       .ReturnType(EdmDataTypes.Int32.Nullable());

            if (addAnnotations)
            {
                serviceOp.MimeType("img/jpeg");
            }

            return(model);
        }
        public void ConvertPrimitiveTypeProperties()
        {
            var taupoModel = new EntityModelSchema()
            {
                new EntityType("NS1", "Entity1")
                {
                    new MemberProperty("p0", EdmDataTypes.Binary(100, true)),
                    new MemberProperty("p1", EdmDataTypes.Boolean),
                    new MemberProperty("p2", EdmDataTypes.Byte),
                    new MemberProperty("p4", EdmDataTypes.DateTimeOffset(7)),
                    new MemberProperty("p5", EdmDataTypes.Decimal(10, 2)),
                    new MemberProperty("p6", EdmDataTypes.Double),
                    new MemberProperty("p7", EdmDataTypes.Guid),
                    new MemberProperty("p8", EdmDataTypes.Int16),
                    new MemberProperty("p9", EdmDataTypes.Int32),
                    new MemberProperty("p10", EdmDataTypes.Int64),
                    new MemberProperty("p11", EdmDataTypes.SByte),
                    new MemberProperty("p12", EdmDataTypes.Single),
                    new MemberProperty("p13", EdmDataTypes.String(50, true, false)),
                    new MemberProperty("p14", EdmDataTypes.Time(11)),
                },
            };

            IEdmModel result = this.converter.ConvertToEdmModel(taupoModel);

            IEdmEntityType entity = result.SchemaElements.OfType <IEdmEntityType>().First();

            Assert.AreEqual(14, entity.DeclaredStructuralProperties().Count());
            Assert.AreEqual("Edm.Binary", entity.DeclaredStructuralProperties().ElementAt(0).Type.FullName());
            Assert.AreEqual("Edm.Boolean", entity.DeclaredStructuralProperties().ElementAt(1).Type.FullName());
            Assert.AreEqual("Edm.Byte", entity.DeclaredStructuralProperties().ElementAt(2).Type.FullName());
            Assert.AreEqual("Edm.DateTimeOffset", entity.DeclaredStructuralProperties().ElementAt(3).Type.FullName());
            Assert.AreEqual("Edm.Decimal", entity.DeclaredStructuralProperties().ElementAt(4).Type.FullName());
            Assert.AreEqual("Edm.Double", entity.DeclaredStructuralProperties().ElementAt(5).Type.FullName());
            Assert.AreEqual("Edm.Guid", entity.DeclaredStructuralProperties().ElementAt(6).Type.FullName());
            Assert.AreEqual("Edm.Int16", entity.DeclaredStructuralProperties().ElementAt(7).Type.FullName());
            Assert.AreEqual("Edm.Int32", entity.DeclaredStructuralProperties().ElementAt(8).Type.FullName());
            Assert.AreEqual("Edm.Int64", entity.DeclaredStructuralProperties().ElementAt(9).Type.FullName());
            Assert.AreEqual("Edm.SByte", entity.DeclaredStructuralProperties().ElementAt(10).Type.FullName());
            Assert.AreEqual("Edm.Single", entity.DeclaredStructuralProperties().ElementAt(11).Type.FullName());
            Assert.AreEqual("Edm.String", entity.DeclaredStructuralProperties().ElementAt(12).Type.FullName());
            Assert.AreEqual("Edm.Duration", entity.DeclaredStructuralProperties().ElementAt(13).Type.FullName());

            foreach (var p in entity.DeclaredStructuralProperties())
            {
                Assert.AreEqual(EdmTypeKind.Primitive, p.Type.TypeKind());
                Assert.IsFalse(p.Type.IsNullable);
            }
        }
示例#17
0
        private string GetPrimitiveDataTypeName(PrimitiveDataType primitiveType)
        {
            var enumDataType = primitiveType as EnumDataType;

            if (enumDataType != null)
            {
                return(this.GetFullyQualifiedName(enumDataType.Definition));
            }

            if (this.OutputFullNameForPrimitiveDataType)
            {
                return(EdmDataTypes.GetEdmFullName(primitiveType));
            }

            return(EdmDataTypes.GetEdmName(primitiveType));
        }
        public static DataType ConvertToTaupoPrimitiveDataType(IEdmPrimitiveTypeReference edmPrimitiveTypeReference)
        {
            PrimitiveDataType    result        = null;
            EdmPrimitiveTypeKind primitiveKind = edmPrimitiveTypeReference.PrimitiveKind();

            if (!facetlessDataTypeLookup.TryGetValue(primitiveKind, out result))
            {
                switch (primitiveKind)
                {
                case EdmPrimitiveTypeKind.Binary:
                    var edmBinary = edmPrimitiveTypeReference.AsBinary();
                    result = EdmDataTypes.Binary(edmBinary.MaxLength);
                    break;

                case EdmPrimitiveTypeKind.DateTimeOffset:
                    var edmDateTimeOffset = edmPrimitiveTypeReference.AsTemporal();
                    result = EdmDataTypes.DateTimeOffset(edmDateTimeOffset.Precision);
                    break;

                case EdmPrimitiveTypeKind.Decimal:
                    var edmDecimal = edmPrimitiveTypeReference.AsDecimal();
                    result = EdmDataTypes.Decimal(edmDecimal.Precision, edmDecimal.Scale);
                    break;

                case EdmPrimitiveTypeKind.String:
                    var edmString = edmPrimitiveTypeReference.AsString();
                    var maxLength = edmString.MaxLength;
                    if (edmString.IsUnbounded == true)
                    {
                        maxLength = MaxLengthMaxTaupoDefaultValue;
                    }

                    result = EdmDataTypes.String(maxLength, edmString.IsUnicode);
                    break;

                case EdmPrimitiveTypeKind.Duration:
                    var edmTime = edmPrimitiveTypeReference.AsTemporal();
                    result = EdmDataTypes.Time(edmTime.Precision);
                    break;

                default:
                    throw new TaupoInvalidOperationException("unexpected Edm Primitive Type Kind: " + primitiveKind);
                }
            }

            return(result.Nullable(edmPrimitiveTypeReference.IsNullable));
        }
示例#19
0
        private string GetEdmNameForUnderlyingType(Type underlyingType)
        {
            var edmPrimitiveDataType = EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest)
                                       .SingleOrDefault(t => t.HasFacet <PrimitiveClrTypeFacet>() && t.GetFacet <PrimitiveClrTypeFacet>().Value == underlyingType);

            if (edmPrimitiveDataType != null)
            {
                if (this.OutputFullNameForPrimitiveDataType)
                {
                    return(EdmDataTypes.GetEdmFullName(edmPrimitiveDataType));
                }

                return(EdmDataTypes.GetEdmName(edmPrimitiveDataType));
            }

            return(underlyingType.Name);
        }
示例#20
0
        /// <summary>
        /// Given the full name of an EDM primitive type, returns that type.
        /// </summary>
        /// <param name="edmTypeName">The full name of the EDM primitive type to get.</param>
        /// <returns>The EDM primitive type of the specified name; or null if no EDM primitive type of the specified name was found.</returns>
        public static PrimitiveDataType GetPrimitiveEdmType(string edmTypeName)
        {
            ExceptionUtilities.CheckArgumentNotNull(edmTypeName, "edmTypeName");

            PrimitiveDataType primitiveDataType = EdmDataTypes.GetAllPrimitiveTypes(EdmVersion.Latest).SingleOrDefault(t => t.FullEdmName() == edmTypeName);

            // OData only supports nullable versions of Edm.String and Edm.Binary
            if (string.CompareOrdinal(EdmConstants.EdmStringTypeName, edmTypeName) == 0 ||
                string.CompareOrdinal(EdmConstants.EdmBinaryTypeName, edmTypeName) == 0)
            {
                return(primitiveDataType.Nullable());
            }
            else
            {
                return(primitiveDataType);
            }
        }
示例#21
0
            /// <summary>
            /// Resolves the specified data type.
            /// </summary>
            /// <param name="dataType">Data type specification.</param>
            /// <returns>Resolved EDM Type.</returns>
            PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(StringDataType dataType)
            {
                int?           maxLength = null;
                bool?          isUnicode = null;
                MaxLengthFacet maxLengthFacet;
                IsUnicodeFacet isUnicodeFacet;

                if (dataType.TryGetFacet(out maxLengthFacet))
                {
                    maxLength = maxLengthFacet.Value;
                }

                if (dataType.TryGetFacet(out isUnicodeFacet))
                {
                    isUnicode = isUnicodeFacet.Value;
                }

                return(EdmDataTypes.String(maxLength, isUnicode));
            }
示例#22
0
            /// <summary>
            /// Resolves the specified data type.
            /// </summary>
            /// <param name="dataType">Data type specification.</param>
            /// <returns>Resolved EDM Type.</returns>
            PrimitiveDataType IPrimitiveDataTypeVisitor <PrimitiveDataType> .Visit(FixedPointDataType dataType)
            {
                int?precision = null;
                int?scale     = null;

                NumericPrecisionFacet precisionFacet;
                NumericScaleFacet     scaleFacet;

                if (dataType.TryGetFacet(out precisionFacet))
                {
                    precision = precisionFacet.Value;
                }

                if (dataType.TryGetFacet(out scaleFacet))
                {
                    scale = scaleFacet.Value;
                }

                return(EdmDataTypes.Decimal(precision, scale));
            }
示例#23
0
        public static bool IsPromotable(PrimitiveDataType fromType, PrimitiveDataType toType)
        {
            string fromTypeName = EdmDataTypes.GetEdmName(fromType);
            string toTypeName   = EdmDataTypes.GetEdmName(toType);

            if (fromTypeName == toTypeName)
            {
                return(true);
            }
            else
            {
                ICollection <string> promotabilityForType;
                if (promotabilityTable.TryGetValue(fromTypeName, out promotabilityForType) && promotabilityForType.Contains(toTypeName))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#24
0
        /// <summary>
        /// Determines whether the type can be assigned from another.
        /// </summary>
        /// <param name="queryType">Type to assign from.</param>
        /// <returns>True if assignment is possible, false otherwise.</returns>
        public override bool IsAssignableFrom(QueryType queryType)
        {
            if (object.ReferenceEquals(this, queryType))
            {
                return(true);
            }

            // if it is not a mapped scalar type, then it is not assignable
            var mappedScalarType = queryType as QueryMappedScalarType;

            if (mappedScalarType == null)
            {
                return(false);
            }

            var targetSpatialDataType = mappedScalarType.ModelType as SpatialDataType;
            var spatialDataType       = this.ModelType as SpatialDataType;

            // The spatial types have the same clrtype - DbGeometry or DbGeography but the strong types aren't assignable from each other.  For example a Point isn't assignable from a LineString.
            if (spatialDataType != null && targetSpatialDataType != null)
            {
                var edmTypeName = spatialDataType.GetFacetValue <EdmTypeNameFacet, string>(string.Empty);
                if (edmTypeName.Equals("Geometry", StringComparison.OrdinalIgnoreCase))
                {
                    return(EdmDataTypes.IsGeometricSpatialType(targetSpatialDataType));
                }

                if (edmTypeName.Equals("Geography", StringComparison.OrdinalIgnoreCase))
                {
                    return(!EdmDataTypes.IsGeometricSpatialType(targetSpatialDataType));
                }

                var targetEdmTypeName = targetSpatialDataType.GetFacetValue <EdmTypeNameFacet, string>(string.Empty);
                return(edmTypeName == targetEdmTypeName);
            }

            // otherwise, fall back to CLR semantics for assignment
            return(this.ClrType.IsAssignableFrom(mappedScalarType.ClrType));
        }
示例#25
0
        /// <summary>
        /// Build the collection of primitive types which will be set on the constructed repository
        /// </summary>
        /// <param name="queryTypeLibrary">Query Type Library to build Types from</param>
        protected override void BuildPrimitiveTypes(QueryTypeLibrary queryTypeLibrary)
        {
            this.intType    = (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Int32);
            this.stringType = (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.String());

            this.PrimitiveTypes = new List <QueryScalarType>()
            {
                // this is just a sample
                this.intType,
                this.stringType,
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Boolean),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.DateTime()),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Decimal()),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Int64),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Int16),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Byte),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Single),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Double),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Binary()),
                (QueryScalarType)queryTypeLibrary.GetDefaultQueryType(EdmDataTypes.Guid),
            };
        }
 /// <summary>
 /// Converts the primitive data type to a clr type
 /// </summary>
 /// <param name="dataType">The data type</param>
 /// <returns>The clr type that corresponds to the primitive data type</returns>
 public Type ToClrType(PrimitiveDataType dataType)
 {
     ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType");
     return(this.ToClrType(EdmDataTypes.GetEdmFullName(dataType)));
 }
示例#27
0
        /// <summary>
        /// Adds and updates existing types in the default model to use Primitive and Complex Collections
        /// </summary>
        /// <param name="model">Model to add fixup to.</param>
        public void Fixup(EntityModelSchema model)
        {
            // Create entityType with all PrimitiveTypes lists
            EntityType allPrimitiveCollectionTypesEntity = new EntityType("AllPrimitiveCollectionTypesEntity");

            allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            allPrimitiveCollectionTypesEntity.Properties[0].IsPrimaryKey = true;
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Property" + i, t));
            }

            model.Add(allPrimitiveCollectionTypesEntity);

            // Create a complexType  with all PrimitiveTypes Bags and primitive properties in it
            ComplexType additionalComplexType = new ComplexType("AdditionalComplexType");

            additionalComplexType.Add(new MemberProperty("Bag1", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())));
            additionalComplexType.Add(new MemberProperty("Bag3", EdmDataTypes.String()));
            model.Add(additionalComplexType);

            // Create a complexType  with all PrimitiveTypes Bags in it
            ComplexType complexPrimitiveCollectionsType = new ComplexType("ComplexTypePrimitiveCollections");

            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                complexPrimitiveCollectionsType.Add(new MemberProperty("Property" + i, t));
            }

            complexPrimitiveCollectionsType.Add(new MemberProperty("ComplexTypeBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(additionalComplexType))));
            model.Add(complexPrimitiveCollectionsType);

            // Add the complexPrimitiveCollectionsType to an entity
            EntityType complexBagsEntity = new EntityType("ComplexBagsEntity");

            complexBagsEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            complexBagsEntity.Properties[0].IsPrimaryKey = true;
            DataType complexDataType = DataTypes.ComplexType.WithDefinition(complexPrimitiveCollectionsType);

            complexBagsEntity.Add(new MemberProperty("CollectionComplexTypePrimitiveCollections", DataTypes.CollectionType.WithElementDataType(complexDataType)));
            complexBagsEntity.Add(new MemberProperty("ComplexTypePrimitiveCollections", complexDataType));

            model.Add(complexBagsEntity);

            int numberOfComplexCollections = 0;

            // Update existing model so that every 3rd complexType is a Collection of ComplexTypes
            foreach (EntityType t in model.EntityTypes)
            {
                foreach (MemberProperty complexProperty in t.Properties.Where(p => p.PropertyType is ComplexDataType).ToList())
                {
                    // Remove existing one
                    t.Properties.Remove(complexProperty);

                    // Add new one
                    t.Properties.Add(new MemberProperty(complexProperty.Name + "Collection", DataTypes.CollectionType.WithElementDataType(complexProperty.PropertyType)));
                    numberOfComplexCollections++;

                    if (numberOfComplexCollections > 4)
                    {
                        break;
                    }
                }

                if (numberOfComplexCollections > 4)
                {
                    break;
                }
            }

            new ResolveReferencesFixup().Fixup(model);

            // ReApply the previously setup namespace on to the new types
            new ApplyDefaultNamespaceFixup(model.EntityTypes.First().NamespaceName).Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);
            new SetDefaultCollectionTypesFixup().Fixup(model);
        }
示例#28
0
        /// <summary>
        /// Generate the model.
        /// </summary>
        /// <returns> Valid <see cref="EntityModelSchema"/>.</returns>
        public EntityModelSchema GenerateModel()
        {
            var model = new EntityModelSchema()
            {
                new EntityType("Movie")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),
                    new MemberProperty("ReleaseYear", DataTypes.DateTime),
                    new MemberProperty("Trailer", DataTypes.Stream),
                    new MemberProperty("FullMovie", DataTypes.Stream),
                    new NavigationProperty("Director", "Movie_Director", "Movie", "Director"),
                    new NavigationProperty("Actors", "Movie_Actors", "Movie", "Actor"),
                    new NavigationProperty("Awards", "Movie_Awards", "Movie", "Award"),
                    new HasStreamAnnotation(),
                },
                new EntityType("Person")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FirstName", DataTypes.String),
                    new MemberProperty("SurName", DataTypes.String),
                    new MemberProperty("DateOfBirth", DataTypes.DateTime),
                    new MemberProperty("EmailBag", DataTypes.CollectionType.WithElementDataType(DataTypes.String.WithMaxLength(32))).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("HomePhone", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("WorkPhone", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("MobilePhoneBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithName("Phone"))),
                    new NavigationProperty("DirectedMovies", "Person_Movies", "Person", "Movie"),
                    new NavigationProperty("Awards", "Person_Awards", "Person", "Award"),
                },
                new EntityType("Award")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),
                    new MemberProperty("AwardsDate", DataTypes.DateTime),
                    new MemberProperty("AwardedBy", DataTypes.String),
                    new MemberProperty("AwardKindBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithName("AwardKind"))),
                    new NavigationProperty("Movie", "Movie_Awards", "Award", "Movie"),
                    new NavigationProperty("Recipient", "Person_Awards", "Award", "Person")
                },
                new EntityType("Actor")
                {
                    BaseType = "Person",
                },
                new EntityType("MegaStar")
                {
                    BaseType = "Actor",
                },
                new EntityType("AllBagTypes")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("BagOfPrimitiveToLinks", DataTypes.CollectionType.WithElementDataType(DataTypes.String)).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("BagOfDecimals", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Decimal())),
                    new MemberProperty("BagOfDoubles", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Double)),
                    new MemberProperty("BagOfSingles", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Single)),
                    new MemberProperty("BagOfBytes", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Byte)),
                    new MemberProperty("BagOfInt16s", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int16)),
                    new MemberProperty("BagOfInt32s", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int32)),
                    new MemberProperty("BagOfDates", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())),
                    new MemberProperty("BagOfGuids", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Guid)),
                },
                new ComplexType("Phone")
                {
                    new MemberProperty("PhoneNumber", DataTypes.String.WithMaxLength(16)),
                    new MemberProperty("Extension", DataTypes.String.WithMaxLength(16).Nullable(true)),
                },
                new ComplexType("AwardKind")
                {
                    new MemberProperty("Name", DataTypes.String.WithMaxLength(16)),
                    new MemberProperty("Type", DataTypes.String.WithMaxLength(16).Nullable(true)),
                },
                new AssociationType("Movie_Director")
                {
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.Many),
                    new AssociationEnd("Director", "Person", EndMultiplicity.One),
                },
                new AssociationType("Movie_Actors")
                {
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.Many),
                    new AssociationEnd("Actor", "Actor", EndMultiplicity.Many),
                },
                new AssociationType("Movie_Awards")
                {
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Award", "Award", EndMultiplicity.Many),
                },
                new AssociationType("Person_Awards")
                {
                    new AssociationEnd("Person", "Person", EndMultiplicity.One),
                    new AssociationEnd("Award", "Award", EndMultiplicity.Many),
                },
                new AssociationType("Person_Movies")
                {
                    new AssociationEnd("Person", "Person", EndMultiplicity.One),
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.Many),
                },
            };

            // Add a service operation for each base entity type
            new AddRootServiceOperationsFixup().Fixup(model);

            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("Netflix").Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);

            return(model);
        }
        public EntityModelSchema GenerateModel()
        {
            var model = new EntityModelSchema()
            {
                new EntityType("Customer")
                {
                    new MemberProperty("CustomerId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String.WithMaxLength(100)).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("ContactInfo", DataTypes.ComplexType.WithName("ContactDetails")),
                    new MemberProperty("Auditing", DataTypes.ComplexType.WithName("AuditInfo")),
                    new NavigationProperty("Orders", "Customer_Orders", "Customer", "Order"),
                    new NavigationProperty("Logins", "Customer_Logins", "Customer", "Logins"),
                    new NavigationProperty("Husband", "Husband_Wife", "Wife", "Husband"),
                    new NavigationProperty("Wife", "Husband_Wife", "Husband", "Wife"),
                    new NavigationProperty("Info", "Customer_CustomerInfo", "Customer", "Info"),
                },
                new ComplexType("Aliases")
                {
                    new MemberProperty("AlternativeName", DataTypes.String.WithMaxLength(10)),
                },
                new ComplexType("Phone")
                {
                    new MemberProperty("PhoneNumber", DataTypes.String.WithMaxLength(16)),
                    new MemberProperty("Extension", DataTypes.String.WithMaxLength(16).Nullable(true)),
                },
                new ComplexType("ContactDetails")
                {
                    new MemberProperty("Email", DataTypes.String.WithMaxLength(32)),
                    new MemberProperty("AlternativeName", DataTypes.String.WithMaxLength(10)),
                    new MemberProperty("ContactAlias", DataTypes.ComplexType.WithName("Aliases")),
                    new MemberProperty("HomePhone", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("WorkPhone", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("MobilePhone", DataTypes.ComplexType.WithName("Phone")),
                },
                new ComplexType("ComplexToCategory")
                {
                    new MemberProperty("Term", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("Scheme", DataTypes.String).WithDataGenerationHints(DataGenerationHints.StringPrefixHint("http://"), DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(10)),
                    new MemberProperty("Label", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                },
                new EntityType("Barcode")
                {
                    new MemberProperty("Code", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ProductId", DataTypes.Integer),
                    new MemberProperty("Text", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MinLength(3)),
                    new NavigationProperty("Product", "Product_Barcodes", "Barcodes", "Product"),
                    new NavigationProperty("BadScans", "Barcode_IncorrectScanExpected", "Barcode", "Expected"),
                    new NavigationProperty("Detail", "Barcode_BarcodeDetail", "Barcode", "BarcodeDetail"),
                },
                new EntityType("IncorrectScan")
                {
                    new MemberProperty("IncorrectScanId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ExpectedCode", DataTypes.Integer),
                    new MemberProperty("ActualCode", DataTypes.Integer.Nullable(true)),
                    new MemberProperty("ScanDate", DataTypes.DateTime),
                    new MemberProperty("Details", DataTypes.String),
                    new NavigationProperty("ExpectedBarcode", "Barcode_IncorrectScanExpected", "Expected", "Barcode"),
                    new NavigationProperty("ActualBarcode", "Barcode_IncorrectScanActual", "Actual", "Barcode"),
                },
                new EntityType("BarcodeDetail")
                {
                    new MemberProperty("Code", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("RegisteredTo", DataTypes.String),
                },
                new EntityType("Complaint")
                {
                    new MemberProperty("ComplaintId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("CustomerId", DataTypes.Integer.Nullable(true)),
                    new MemberProperty("Logged", DataTypes.DateTime),
                    new MemberProperty("Details", DataTypes.String),
                    new NavigationProperty("Customer", "Customer_Complaints", "Complaints", "Customer"),
                    new NavigationProperty("Resolution", "Complaint_Resolution", "Complaint", "Resolution"),
                },
                new EntityType("Resolution")
                {
                    new MemberProperty("ResolutionId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Details", DataTypes.String),
                    new NavigationProperty("Complaint", "Complaint_Resolution", "Resolution", "Complaint"),
                },
                new EntityType("Login")
                {
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("CustomerId", DataTypes.Integer),
                    new NavigationProperty("Customer", "Customer_Logins", "Logins", "Customer"),
                    new NavigationProperty("LastLogin", "Login_LastLogin", "Login", "LastLogin"),
                    new NavigationProperty("SentMessages", "Login_SentMessages", "Sender", "Message"),
                    new NavigationProperty("ReceivedMessages", "Login_ReceivedMessages", "Recipient", "Message"),
                    new NavigationProperty("Orders", "Login_Orders", "Login", "Orders"),
                },
                new EntityType("SuspiciousActivity")
                {
                    new MemberProperty("SuspiciousActivityId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Activity", DataTypes.String),
                },
                new EntityType("SmartCard")
                {
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("CardSerial", DataTypes.String),
                    new MemberProperty("Issued", DataTypes.DateTime),
                    new NavigationProperty("Login", "Login_SmartCard", "SmartCard", "Login"),
                    new NavigationProperty("LastLogin", "LastLogin_SmartCard", "SmartCard", "LastLogin"),
                },
                new EntityType("RSAToken")
                {
                    new MemberProperty("Serial", DataTypes.String.WithMaxLength(20))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Issued", DataTypes.DateTime),
                    new NavigationProperty("Login", "Login_RSAToken", "RSAToken", "Login"),
                },
                new EntityType("PasswordReset")
                {
                    new MemberProperty("ResetNo", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("TempPassword", DataTypes.String),
                    new MemberProperty("EmailedTo", DataTypes.String),
                    new NavigationProperty("Login", "Login_PasswordResets", "PasswordResets", "Login"),
                },
                new EntityType("PageView")
                {
                    new MemberProperty("PageViewId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50)),
                    new MemberProperty("Viewed", DataTypes.DateTime),
                    new MemberProperty("PageUrl", DataTypes.String.WithMaxLength(500)).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MinLength(3)),
                    new NavigationProperty("Login", "Login_PageViews", "PageViews", "Login"),
                },
                new EntityType("ProductPageView")
                {
                    BaseType   = "PageView",
                    Properties =
                    {
                        new MemberProperty("ProductId", DataTypes.Integer),
                    },
                },
                new EntityType("LastLogin")
                {
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("LoggedIn", DataTypes.DateTime),
                    new MemberProperty("LoggedOut", DataTypes.DateTime.Nullable(true)),
                    new NavigationProperty("Login", "Login_LastLogin", "LastLogin", "Login"),
                },
                new EntityType("Message")
                {
                    new MemberProperty("MessageId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FromUsername", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ToUsername", DataTypes.String.WithMaxLength(50)),
                    new MemberProperty("Sent", DataTypes.DateTime),

                    // Marking as NonNullable until null epm is allowed
                    new MemberProperty("Subject", DataTypes.String.NotNullable()).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("Body", DataTypes.String.Nullable(true)),
                    new MemberProperty("IsRead", DataTypes.Boolean),
                    new NavigationProperty("Sender", "Login_SentMessages", "Message", "Sender"),
                    new NavigationProperty("Recipient", "Login_ReceivedMessages", "Message", "Recipient"),
                },
                new EntityType("Order")
                {
                    new MemberProperty("OrderId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("CustomerId", DataTypes.Integer.Nullable(true)),
                    new MemberProperty("Concurrency", DataTypes.ComplexType.WithName("ConcurrencyInfo")),
                    new NavigationProperty("Customer", "Customer_Orders", "Order", "Customer"),
                    new NavigationProperty("OrderLines", "Order_OrderLines", "Order", "OrderLines"),
                    new NavigationProperty("Notes", "Order_OrderNotes", "Order", "Notes"),
                    new NavigationProperty("Login", "Login_Orders", "Orders", "Login"),
                },
                new EntityType("OrderNote")
                {
                    new MemberProperty("NoteId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Note", DataTypes.String),
                    new NavigationProperty("Order", "Order_OrderNotes", "Notes", "Order"),
                },
                new EntityType("OrderQualityCheck")
                {
                    new MemberProperty("OrderId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("CheckedBy", DataTypes.String),
                    new MemberProperty("CheckedDateTime", DataTypes.DateTime),
                    new NavigationProperty("Order", "Order_QualityCheck", "QualityCheck", "Order"),
                },
                new EntityType("OrderLine")
                {
                    new MemberProperty("OrderId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Quantity", DataTypes.Integer),
                    new MemberProperty("ConcurrencyToken", DataTypes.String)
                    {
                        Annotations = { new ConcurrencyTokenAnnotation() }
                    },
                    new NavigationProperty("Order", "Order_OrderLines", "OrderLines", "Order"),
                    new NavigationProperty("Product", "Product_OrderLines", "OrderLines", "Product"),
                },
                new EntityType("BackOrderLine")
                {
                    BaseType = "OrderLine"
                },
                new EntityType("BackOrderLine2")
                {
                    BaseType = "BackOrderLine",
                },
                new ComplexType("Dimensions")
                {
                    new MemberProperty("Width", DataTypes.FixedPoint.WithPrecision(10).WithScale(3)),
                    new MemberProperty("Height", DataTypes.FixedPoint.WithPrecision(10).WithScale(3)),
                    new MemberProperty("Depth", DataTypes.FixedPoint.WithPrecision(10).WithScale(3)),
                },
                new EntityType("Product")
                {
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Description", DataTypes.String.Nullable(true).WithUnicodeSupport(true).WithMaxLength(1000)),
                    new MemberProperty("Dimensions", DataTypes.ComplexType.WithName("Dimensions")),
                    new MemberProperty("BaseConcurrency", DataTypes.String)
                    {
                        Annotations = { new ConcurrencyTokenAnnotation() }
                    },
                    new MemberProperty("ComplexConcurrency", DataTypes.ComplexType.WithName("ConcurrencyInfo")),
                    new MemberProperty("NestedComplexConcurrency", DataTypes.ComplexType.WithName("AuditInfo")),
                    new NavigationProperty("RelatedProducts", "Products_RelatedProducts", "Product", "RelatedProducts"),
                    new NavigationProperty("Suppliers", "Products_Suppliers", "Products", "Suppliers"),
                    new NavigationProperty("Detail", "Product_ProductDetail", "Product", "ProductDetail"),
                    new NavigationProperty("Reviews", "Product_ProductReview", "Product", "ProductReview"),
                    new NavigationProperty("Photos", "Product_ProductPhoto", "Product", "ProductPhoto"),
                    new NavigationProperty("Barcodes", "Product_Barcodes", "Product", "Barcodes"),
                },
                new EntityType("DiscontinuedProduct")
                {
                    BaseType   = "Product",
                    Properties =
                    {
                        new MemberProperty("Discontinued",         DataTypes.DateTime),
                        new MemberProperty("ReplacementProductId", DataTypes.Integer.Nullable()),
                    },
                },
                new EntityType("ProductDetail")
                {
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Details", DataTypes.String),
                    new NavigationProperty("Product", "Product_ProductDetail", "ProductDetail", "Product"),
                },
                new EntityType("ProductReview")
                {
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ReviewId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Review", DataTypes.String),
                    new NavigationProperty("Product", "Product_ProductReview", "ProductReview", "Product"),
                    new NavigationProperty("Features", "ProductWebFeature_ProductReview", "ProductReview", "ProductWebFeature"),
                },
                new EntityType("ProductPhoto")
                {
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("PhotoId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Photo", DataTypes.Binary),
                    new NavigationProperty("Features", "ProductWebFeature_ProductPhoto", "ProductPhoto", "ProductWebFeature"),
                },
                new EntityType("ProductWebFeature")
                {
                    new MemberProperty("FeatureId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ProductId", DataTypes.Integer.Nullable()),
                    new MemberProperty("PhotoId", DataTypes.Integer.Nullable()),
                    new MemberProperty("ReviewId", DataTypes.Integer),
                    new MemberProperty("Heading", DataTypes.String),
                    new NavigationProperty("Review", "ProductWebFeature_ProductReview", "ProductWebFeature", "ProductReview"),
                    new NavigationProperty("Photo", "ProductWebFeature_ProductPhoto", "ProductWebFeature", "ProductPhoto"),
                },
                new EntityType("Supplier")
                {
                    new MemberProperty("SupplierId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),
                    new NavigationProperty("Products", "Products_Suppliers", "Suppliers", "Products"),
                    new NavigationProperty("Logo", "Supplier_SupplierLogo", "Supplier", "Logo"),
                },
                new EntityType("SupplierLogo")
                {
                    new MemberProperty("SupplierId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Logo", DataTypes.Binary.WithMaxLength(500)),
                },
                new EntityType("SupplierInfo")
                {
                    new MemberProperty("SupplierInfoId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Information", DataTypes.String),
                    new NavigationProperty("Supplier", "Supplier_SupplierInfo", "Info", "Supplier"),
                },
                new EntityType("CustomerInfo")
                {
                    new MemberProperty("CustomerInfoId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Information", DataTypes.String),
                },
                new EntityType("Computer")
                {
                    new MemberProperty("ComputerId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String),
                    new NavigationProperty("ComputerDetail", "Computer_ComputerDetail", "Computer", "ComputerDetail"),
                },
                new EntityType("ComputerDetail")
                {
                    new MemberProperty("ComputerDetailId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Manufacturer", DataTypes.String),
                    new MemberProperty("Model", DataTypes.String),
                    new MemberProperty("Serial", DataTypes.String),
                    new MemberProperty("Specifications", DataTypes.String),
                    new MemberProperty("PurchaseDate", DataTypes.DateTime),
                    new MemberProperty("Dimensions", DataTypes.ComplexType.WithName("Dimensions")),
                    new NavigationProperty("Computer", "Computer_ComputerDetail", "ComputerDetail", "Computer"),
                    new HasStreamAnnotation(),
                },
                new EntityType("Driver")
                {
                    new MemberProperty("Name", DataTypes.String.WithMaxLength(100))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("BirthDate", DataTypes.DateTime),
                    new NavigationProperty("License", "Driver_License", "Driver", "License"),
                },
                new EntityType("License")
                {
                    new MemberProperty("Name", DataTypes.String.WithMaxLength(100))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("LicenseNumber", DataTypes.String),
                    new MemberProperty("LicenseClass", DataTypes.String),
                    new MemberProperty("Restrictions", DataTypes.String),
                    new MemberProperty("ExpirationDate", DataTypes.DateTime),
                    new NavigationProperty("Driver", "Driver_License", "License", "Driver"),
                },
                new EntityType("MappedEntityType")
                {
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Href", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("Title", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("HrefLang", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("Type", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("Length", DataTypes.Integer).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MinValue <int>(100), DataGenerationHints.MaxValue <int>(200)),
                    new MemberProperty("PrimitiveToLinks", DataTypes.String),
                    new MemberProperty("Decimals", EdmDataTypes.Decimal()),
                    new MemberProperty("Doubles", EdmDataTypes.Double),
                    new MemberProperty("Singles", EdmDataTypes.Single),
                    new MemberProperty("Bytes", EdmDataTypes.Byte),
                    new MemberProperty("Int16s", EdmDataTypes.Int16),
                    new MemberProperty("Int32s", EdmDataTypes.Int32),
                    new MemberProperty("Int64s", EdmDataTypes.Int64),
                    new MemberProperty("Guids", EdmDataTypes.Guid),
                    new MemberProperty("ComplexToCategories", DataTypes.ComplexType.WithName("ComplexToCategory")),
                },
                new EntityType("Car")
                {
                    new MemberProperty("VIN", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Description", DataTypes.String.WithMaxLength(100).Nullable(true)),
                    new HasStreamAnnotation(),
                },
                new ComplexType("AuditInfo")
                {
                    new MemberProperty("ModifiedDate", DataTypes.DateTime),
                    new MemberProperty("ModifiedBy", DataTypes.String.WithMaxLength(50)),
                    new MemberProperty("Concurrency", DataTypes.ComplexType.WithName("ConcurrencyInfo")),
                },
                new ComplexType("ConcurrencyInfo")
                {
                    new MemberProperty("Token", DataTypes.String.WithMaxLength(20)),
                    new MemberProperty("QueriedDateTime", DataTypes.DateTime.Nullable(true)),
                },
                new AssociationType("Customer_Complaints")
                {
                    new AssociationEnd("Customer", "Customer", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Complaints", "Complaint", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Complaints", "CustomerId")
                    .ReferencesPrincipalProperties("Customer", "CustomerId"),
                },
                new AssociationType("Login_SentMessages")
                {
                    new AssociationEnd("Sender", "Login", EndMultiplicity.One),
                    new AssociationEnd("Message", "Message", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Message", "FromUsername")
                    .ReferencesPrincipalProperties("Sender", "Username"),
                },
                new AssociationType("Login_ReceivedMessages")
                {
                    new AssociationEnd("Recipient", "Login", EndMultiplicity.One),
                    new AssociationEnd("Message", "Message", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Message", "ToUsername")
                    .ReferencesPrincipalProperties("Recipient", "Username"),
                },
                new AssociationType("Customer_CustomerInfo")
                {
                    new AssociationEnd("Customer", "Customer", EndMultiplicity.One),
                    new AssociationEnd("Info", "CustomerInfo", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Supplier_SupplierInfo")
                {
                    new AssociationEnd("Supplier", "Supplier", EndMultiplicity.One, OperationAction.Cascade),
                    new AssociationEnd("Info", "SupplierInfo", EndMultiplicity.Many),
                },
                new AssociationType("Login_Orders")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Orders", "Order", EndMultiplicity.Many),
                },
                new AssociationType("Order_OrderNotes")
                {
                    new AssociationEnd("Order", "Order", EndMultiplicity.One, OperationAction.Cascade),
                    new AssociationEnd("Notes", "OrderNote", EndMultiplicity.Many),
                },
                new AssociationType("Order_QualityCheck")
                {
                    new AssociationEnd("Order", "Order", EndMultiplicity.One),
                    new AssociationEnd("QualityCheck", "OrderQualityCheck", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("QualityCheck", "OrderId")
                    .ReferencesPrincipalProperties("Order", "OrderId"),
                },
                new AssociationType("Supplier_SupplierLogo")
                {
                    new AssociationEnd("Supplier", "Supplier", EndMultiplicity.One),
                    new AssociationEnd("Logo", "SupplierLogo", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("Logo", "SupplierId")
                    .ReferencesPrincipalProperties("Supplier", "SupplierId"),
                },
                new AssociationType("Customer_Orders")
                {
                    new AssociationEnd("Customer", "Customer", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Order", "Order", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Order", "CustomerId")
                    .ReferencesPrincipalProperties("Customer", "CustomerId"),
                },
                new AssociationType("Customer_Logins")
                {
                    new AssociationEnd("Customer", "Customer", EndMultiplicity.One),
                    new AssociationEnd("Logins", "Login", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Logins", "CustomerId")
                    .ReferencesPrincipalProperties("Customer", "CustomerId"),
                },
                new AssociationType("Login_LastLogin")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("LastLogin", "LastLogin", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("LastLogin", "Username")
                    .ReferencesPrincipalProperties("Login", "Username"),
                },
                new AssociationType("LastLogin_SmartCard")
                {
                    new AssociationEnd("LastLogin", "LastLogin", EndMultiplicity.ZeroOne)
                    {
                        Annotations = { new PrincipalAnnotation() }
                    },
                    new AssociationEnd("SmartCard", "SmartCard", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Order_OrderLines")
                {
                    new AssociationEnd("Order", "Order", EndMultiplicity.One),
                    new AssociationEnd("OrderLines", "OrderLine", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("OrderLines", "OrderId")
                    .ReferencesPrincipalProperties("Order", "OrderId"),
                },
                new AssociationType("Product_OrderLines")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("OrderLines", "OrderLine", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("OrderLines", "ProductId")
                    .ReferencesPrincipalProperties("Product", "ProductId"),
                },
                new AssociationType("Products_Suppliers")
                {
                    new AssociationEnd("Products", "Product", EndMultiplicity.Many),
                    new AssociationEnd("Suppliers", "Supplier", EndMultiplicity.Many),
                },
                new AssociationType("Products_RelatedProducts")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("RelatedProducts", "Product", EndMultiplicity.Many),
                },
                new AssociationType("Product_ProductDetail")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("ProductDetail", "ProductDetail", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("ProductDetail", "ProductId")
                    .ReferencesPrincipalProperties("Product", "ProductId"),
                },
                new AssociationType("Product_ProductReview")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("ProductReview", "ProductReview", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("ProductReview", "ProductId")
                    .ReferencesPrincipalProperties("Product", "ProductId"),
                },
                new AssociationType("Product_ProductPhoto")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("ProductPhoto", "ProductPhoto", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("ProductPhoto", "ProductId")
                    .ReferencesPrincipalProperties("Product", "ProductId"),
                },
                new AssociationType("ProductWebFeature_ProductPhoto")
                {
                    new AssociationEnd("ProductWebFeature", "ProductWebFeature", EndMultiplicity.Many),
                    new AssociationEnd("ProductPhoto", "ProductPhoto", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("ProductWebFeature", "PhotoId", "ProductId")
                    .ReferencesPrincipalProperties("ProductPhoto", "PhotoId", "ProductId"),
                },
                new AssociationType("ProductWebFeature_ProductReview")
                {
                    new AssociationEnd("ProductWebFeature", "ProductWebFeature", EndMultiplicity.Many),
                    new AssociationEnd("ProductReview", "ProductReview", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("ProductWebFeature", "ReviewId", "ProductId")
                    .ReferencesPrincipalProperties("ProductReview", "ReviewId", "ProductId"),
                },
                new AssociationType("Complaint_Resolution")
                {
                    new AssociationEnd("Complaint", "Complaint", EndMultiplicity.One),
                    new AssociationEnd("Resolution", "Resolution", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Barcode_IncorrectScanExpected")
                {
                    new AssociationEnd("Barcode", "Barcode", EndMultiplicity.One),
                    new AssociationEnd("Expected", "IncorrectScan", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Expected", "ExpectedCode")
                    .ReferencesPrincipalProperties("Barcode", "Code"),
                },
                new AssociationType("Husband_Wife")
                {
                    new AssociationEnd("Husband", "Customer", EndMultiplicity.ZeroOne)
                    {
                        Annotations = { new PrincipalAnnotation() }
                    },
                    new AssociationEnd("Wife", "Customer", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Barcode_IncorrectScanActual")
                {
                    new AssociationEnd("Barcode", "Barcode", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Actual", "IncorrectScan", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Actual", "ActualCode")
                    .ReferencesPrincipalProperties("Barcode", "Code"),
                },
                new AssociationType("Product_Barcodes")
                {
                    new AssociationEnd("Product", "Product", EndMultiplicity.One),
                    new AssociationEnd("Barcodes", "Barcode", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("Barcodes", "ProductId")
                    .ReferencesPrincipalProperties("Product", "ProductId"),
                },
                new AssociationType("Barcode_BarcodeDetail")
                {
                    new AssociationEnd("Barcode", "Barcode", EndMultiplicity.One),
                    new AssociationEnd("BarcodeDetail", "BarcodeDetail", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("BarcodeDetail", "Code")
                    .ReferencesPrincipalProperties("Barcode", "Code"),
                },
                new AssociationType("Login_SuspiciousActivity")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Activity", "SuspiciousActivity", EndMultiplicity.Many),
                },
                new AssociationType("Login_RSAToken")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("RSAToken", "RSAToken", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Login_SmartCard")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("SmartCard", "SmartCard", EndMultiplicity.ZeroOne),
                    new ReferentialConstraint()
                    .WithDependentProperties("SmartCard", "Username")
                    .ReferencesPrincipalProperties("Login", "Username"),
                },
                new AssociationType("Login_PasswordResets")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("PasswordResets", "PasswordReset", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("PasswordResets", "Username")
                    .ReferencesPrincipalProperties("Login", "Username"),
                },

                new AssociationType("Login_PageViews")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("PageViews", "PageView", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("PageViews", "Username")
                    .ReferencesPrincipalProperties("Login", "Username"),
                },
                new AssociationType("Computer_ComputerDetail")
                {
                    new AssociationEnd("Computer", "Computer", EndMultiplicity.One)
                    {
                        Annotations = { new PrincipalAnnotation() }
                    },
                    new AssociationEnd("ComputerDetail", "ComputerDetail", EndMultiplicity.One),
                },
                new AssociationType("Driver_License")
                {
                    new AssociationEnd("Driver", "Driver", EndMultiplicity.One),
                    new AssociationEnd("License", "License", EndMultiplicity.One),
                    new ReferentialConstraint()
                    .WithDependentProperties("License", "Name")
                    .ReferencesPrincipalProperties("Driver", "Name"),
                },
            };

            // Apply default fixups
            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("AstoriaPhoneModelGenerator").Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);

            EntityContainer container = model.GetDefaultEntityContainer();

            if (!container.Annotations.OfType <EntitySetRightsAnnotation>().Any())
            {
                container.Annotations.Add(new EntitySetRightsAnnotation()
                {
                    Value = EntitySetRights.All
                });
            }

            return(model);
        }
示例#30
0
        public static IEdmModel BuildTestMetadata(IEntityModelPrimitiveTypeResolver primitiveTypeResolver, IDataServiceProviderFactory provider)
        {
            var schema = new EntityModelSchema()
            {
                new ComplexType("TestNS", "Address")
                {
                    new MemberProperty("City", DataTypes.String.Nullable()),
                    new MemberProperty("Zip", DataTypes.Integer),
                    new ClrTypeAnnotation(typeof(Address))
                },
                new EntityType("TestNS", "Customer")
                {
                    new MemberProperty("ID", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String.Nullable()),
                    new MemberProperty("Emails", DataTypes.CollectionType.WithElementDataType(DataTypes.String.Nullable())),
                    new MemberProperty("Address", DataTypes.ComplexType.WithName("TestNS", "Address")),
                    new ClrTypeAnnotation(typeof(Customer))
                },
                new EntityType("TestNS", "MultiKey")
                {
                    new MemberProperty("KeyB", DataTypes.FloatingPoint)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("KeyA", DataTypes.String.Nullable())
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Keya", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("NonKey", DataTypes.String.Nullable()),
                    new ClrTypeAnnotation(typeof(MultiKey))
                },
                new EntityType("TestNS", "TypeWithPrimitiveProperties")
                {
                    new MemberProperty("ID", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("StringProperty", DataTypes.String.Nullable()),
                    new MemberProperty("BoolProperty", DataTypes.Boolean),
                    new MemberProperty("NullableBoolProperty", DataTypes.Boolean.Nullable()),
                    new MemberProperty("ByteProperty", EdmDataTypes.Byte),
                    new MemberProperty("NullableByteProperty", EdmDataTypes.Byte.Nullable()),
                    new MemberProperty("DateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    new MemberProperty("NullableDateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()),
                    new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
                    new MemberProperty("NullableDecimalProperty", EdmDataTypes.Decimal().Nullable()),
                    new MemberProperty("DoubleProperty", EdmDataTypes.Double),
                    new MemberProperty("NullableDoubleProperty", EdmDataTypes.Double.Nullable()),
                    new MemberProperty("GuidProperty", DataTypes.Guid),
                    new MemberProperty("NullableGuidProperty", DataTypes.Guid.Nullable()),
                    new MemberProperty("Int16Property", EdmDataTypes.Int16),
                    new MemberProperty("NullableInt16Property", EdmDataTypes.Int16.Nullable()),
                    new MemberProperty("Int32Property", DataTypes.Integer),
                    new MemberProperty("NullableInt32Property", DataTypes.Integer.Nullable()),
                    new MemberProperty("Int64Property", EdmDataTypes.Int64),
                    new MemberProperty("NullableInt64Property", EdmDataTypes.Int64.Nullable()),
                    new MemberProperty("SByteProperty", EdmDataTypes.SByte),
                    new MemberProperty("NullableSByteProperty", EdmDataTypes.SByte.Nullable()),
                    new MemberProperty("SingleProperty", EdmDataTypes.Single),
                    new MemberProperty("NullableSingleProperty", EdmDataTypes.Single.Nullable()),
                    new MemberProperty("BinaryProperty", DataTypes.Binary.Nullable()),
                    new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties))
                }
            };

            List <FunctionParameter> defaultParameters = new List <FunctionParameter>()
            {
                new FunctionParameter("soParam", DataTypes.Integer)
            };

            EntitySet       customersSet = new EntitySet("Customers", "Customer");
            EntityContainer container    = new EntityContainer("BinderTestMetadata")
            {
                customersSet,
                new EntitySet("MultiKeys", "MultiKey"),
                new EntitySet("TypesWithPrimitiveProperties", "TypeWithPrimitiveProperties")
            };

            schema.Add(container);

            EntityDataType customerType = DataTypes.EntityType.WithName("TestNS", "Customer");
            EntityDataType multiKeyType = DataTypes.EntityType.WithName("TestNS", "MultiKey");
            EntityDataType entityTypeWithPrimitiveProperties = DataTypes.EntityType.WithName("TestNS", "TypeWithPrimitiveProperties");

            ComplexDataType addressType = DataTypes.ComplexType.WithName("TestNS", "Address");

            addressType.Definition.Add(new ClrTypeAnnotation(typeof(Address)));
            customerType.Definition.Add(new ClrTypeAnnotation(typeof(Customer)));
            multiKeyType.Definition.Add(new ClrTypeAnnotation(typeof(MultiKey)));
            entityTypeWithPrimitiveProperties.Definition.Add(new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties)));

            //container.Add(CreateServiceOperation("VoidServiceOperation", defaultParameters, null, ODataServiceOperationResultKind.Void));
            //container.Add(CreateServiceOperation("DirectValuePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.DirectValue));

            //container.Add(CreateServiceOperation("EnumerationPrimitiveServiceOperation", defaultParameters, DataTypes.CollectionType.WithElementDataType(DataTypes.Integer), ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.Enumeration));

            //container.Add(CreateServiceOperation("QuerySinglePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.QueryWithSingleResult));

            //container.Add(CreateServiceOperation("QueryMultiplePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));

            //container.Add(CreateServiceOperation("ServiceOperationWithNoParameters", new List<FunctionParameter>(), DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation(
            //                        "ServiceOperationWithMultipleParameters",
            //                         new List<FunctionParameter>()
            //                         {
            //                             new FunctionParameter("paramInt", DataTypes.Integer),
            //                             new FunctionParameter("paramString", DataTypes.String.Nullable()),
            //                             new FunctionParameter("paramNullableBool", DataTypes.Boolean.Nullable())
            //                         },
            //                         DataTypes.CollectionOfEntities(customerType.Definition),
            //                         customersSet,
            //                         ODataServiceOperationResultKind.QueryWithMultipleResults));

            new ApplyDefaultNamespaceFixup("TestNS").Fixup(schema);
            new ResolveReferencesFixup().Fixup(schema);
            primitiveTypeResolver.ResolveProviderTypes(schema, new EdmDataTypeResolver());

            return(provider.CreateMetadataProvider(schema));
        }