public EntityModelSchema GenerateModel()
        {
            var model = new EntityModelSchema()
            {
                new EntityType("Customer")
                {
                    Properties =
                    {
                        new MemberProperty("CustomerId",                  DataTypes.Integer)
                        {
                            IsPrimaryKey = true
                        },
                        new MemberProperty("Name",                        DataTypes.String.WithMaxLength(100)).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty),DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                        new MemberProperty("PrimaryContactInfo1",         DataTypes.ComplexType.WithName("ContactDetails"))
                        {
                            Annotations =
                            {
                                new MetadataDeclaredPropertyAnnotation(),
                            }
                        },
                        new MemberProperty("PrimaryContactInfo2",         DataTypes.ComplexType.WithName("ContactDetails")),
                        new MemberProperty("Thumbnail",                   DataTypes.Stream),
                    },
                    IsOpen = true,
                },
                new ComplexType("ContactDetails")
                {
                    new MemberProperty("FirstContacted", DataTypes.Binary),
                    new MemberProperty("LastContacted", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    new MemberProperty("Contacted", DataTypes.DateTime),
                    new MemberProperty("GUID", DataTypes.Guid),
                    new MemberProperty("PreferedContactTime", DataTypes.TimeOfDay),
                    new MemberProperty("Byte", EdmDataTypes.Byte),
                    new MemberProperty("SignedByte", EdmDataTypes.SByte),
                    new MemberProperty("Double", EdmDataTypes.Double),
                    new MemberProperty("Single", EdmDataTypes.Single),
                    new MemberProperty("Short", EdmDataTypes.Int16),
                    new MemberProperty("Int", EdmDataTypes.Int32),
                    new MemberProperty("Long", EdmDataTypes.Int64),
                },
            };

            // Apply default fixups
            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("OpenTypesComplexPropertiesModelGenerator").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);
        }
Ejemplo n.º 2
0
        public EntityModelSchema GenerateModel()
        {
            this.useDataTypes = new Dictionary <DataType, bool>();

            var model = new EntityModelSchema()
            {
                new EntityType("Movie")
                {
                    Annotations =
                    {
                        new HasStreamAnnotation(),
                    },
                    Properties =
                    {
                        new MemberProperty("Id",               EdmDataTypes.Int32)
                        {
                            IsPrimaryKey = true
                        },
                        new MemberProperty("Name",             EdmDataTypes.String()),
                        new MemberProperty("LengthInMinutes",  EdmDataTypes.Int32)
                        {
                            Annotations = { new ConcurrencyTokenAnnotation() }
                        },
                        new MemberProperty("ReleaseYear",      EdmDataTypes.DateTime()),
                        new MemberProperty("Trailer",          EdmDataTypes.Stream),
                        new MemberProperty("FullMovie",        EdmDataTypes.Stream),
                        new MemberProperty("IsAwardWinner",    EdmDataTypes.Boolean),
                        new MemberProperty("AddToQueueValue",  EdmDataTypes.Boolean),
                        new MemberProperty("AddToQueueValue2", EdmDataTypes.Boolean),
                        new MemberProperty("MovieHomePage",    EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls,DataGenerationHints.AnsiString,  DataGenerationHints.MinLength(10)),
                        new MemberProperty("Description",      EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls,DataGenerationHints.AnsiString,  DataGenerationHints.MinLength(10)),
                    },

                    NavigationProperties =
                    {
                        new NavigationProperty("MovieRatings", "MovieRating_Movie", "Movie",  "MovieRating"),
                        new NavigationProperty("Actors",       "Movies_Actors",     "Movies", "Actors"),
                    }
                },
                new ComplexType("Phone")
                {
                    new MemberProperty("PhoneNumber", EdmDataTypes.String()),
                    new MemberProperty("Extension", EdmDataTypes.String().Nullable(true)),
                },
                new ComplexType("ContactDetails")
                {
                    new MemberProperty("PhoneMultiValue", DataTypes.CollectionOfComplex("Phone")),
                },
                new ComplexType("Rating")
                {
                    new MemberProperty("Comments", EdmDataTypes.String()),
                    new MemberProperty("FiveStarRating", EdmDataTypes.Byte),
                    new MemberProperty("Tags", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                },
                new ComplexType("AllSpatialTypesComplex")
                {
                    new MemberProperty("Geog", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPoint", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogLine", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPolygon", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogCollection", EdmDataTypes.GeographyCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPoint", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiLine", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPolygon", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Geom", EdmDataTypes.Geometry.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPoint", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomLine", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPolygon", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomCollection", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPoint", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiLine", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPolygon", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),
                },
                new EntityType("MovieRating")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Rating", DataTypes.ComplexType.WithDefinition("Rating")),
                    new MemberProperty("IsCreatedByCustomer", EdmDataTypes.Boolean),
                    new NavigationProperty("Movie", "MovieRating_Movie", "MovieRating", "Movie"),
                },
                new EntityType("Actor")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FirstName", EdmDataTypes.String()),
                    new MemberProperty("LastName", EdmDataTypes.String()),
                    new MemberProperty("Age", EdmDataTypes.Int32),
                    new MemberProperty("IsAwardWinner", EdmDataTypes.Boolean),
                    new MemberProperty("ContactDetails", DataTypes.ComplexType.WithName("ContactDetails")),
                    new MemberProperty("PrimaryPhoneNumber", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("AdditionalPhoneNumbers", DataTypes.CollectionOfComplex("Phone")),
                    new MemberProperty("AlternativeNames", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                    new NavigationProperty("Movies", "Movies_Actors", "Actors", "Movies"),
                },
                new EntityType("Producer")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("FirstName", EdmDataTypes.String()),
                    new MemberProperty("LastName", EdmDataTypes.String()),
                    new MemberProperty("Toggle", EdmDataTypes.Boolean),
                },
                new EntityType("ExecutiveProducer")
                {
                    BaseType = "Producer"
                },
                new EntityType("ActorMovieRating")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("IsStar", EdmDataTypes.Boolean),
                    new MemberProperty("Rating", DataTypes.ComplexType.WithDefinition("Rating")),
                    new NavigationProperty("Actor", "ActorMovieRating_Actor", "ActorMovieRating", "Actor"),
                    new NavigationProperty("Movie", "ActorMovieRating_Movie", "ActorMovieRating", "Movie"),
                },
                new EntityType("AllTypes")
                {
                    // This EntityType contains only primitive properties
                    new MemberProperty("Id", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ToggleProperty", EdmDataTypes.Boolean),
                    new MemberProperty("BooleanProperty", EdmDataTypes.Boolean),
                    new MemberProperty("StringProperty", EdmDataTypes.String()).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("ByteProperty", EdmDataTypes.Byte),
                    new MemberProperty("DateTimeProperty", EdmDataTypes.DateTime()),
                    new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
                    new MemberProperty("DoubleProperty", EdmDataTypes.Double),
                    new MemberProperty("GuidProperty", EdmDataTypes.Guid),
                    new MemberProperty("Int16Property", EdmDataTypes.Int16),
                    new MemberProperty("Int32Property", EdmDataTypes.Int32),
                    new MemberProperty("Int64Property", EdmDataTypes.Int64),
                    new MemberProperty("SingleProperty", EdmDataTypes.Single),
                    new MemberProperty("BinaryProperty", EdmDataTypes.Binary()),
                    new MemberProperty("DateTimeOffsetProperty", EdmDataTypes.DateTimeOffset().NotNullable()),
                    new MemberProperty("TimeSpanProperty", EdmDataTypes.Time().NotNullable()),
                    new MemberProperty("NullableDateTimeOffsetProperty", EdmDataTypes.DateTimeOffset().Nullable()),
                    new MemberProperty("NullableTimeSpanProperty", EdmDataTypes.Time().Nullable()),

                    new MemberProperty("ByteCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Byte)).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MaxCount(0)),
                    new MemberProperty("DoubleCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Double)).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("Int32CollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int32)).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("StringCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String())).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("DateTimeOffsetCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTimeOffset())).WithDataGenerationHints(DataGenerationHints.NoNulls),
                    new MemberProperty("TimeSpanCollectionProperty", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Time())).WithDataGenerationHints(DataGenerationHints.NoNulls),

                    //// TODO: add the following
                    ////new MemberProperty("NullStringProperty", DataTypes.String).WithDataGenerationHints(DataGenerationHints.AllNulls),
                    ////new MemberProperty("NullBinaryProperty", DataTypes.Binary.WithMaxLength(500)).WithDataGenerationHints(DataGenerationHints.AllNulls),
                },
                new EntityType("AllSpatialTypes")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("ToggleProperty", EdmDataTypes.Boolean),
                    new MemberProperty("Int32Property", EdmDataTypes.Int32),

                    new MemberProperty("Geog", EdmDataTypes.Geography.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPoint", EdmDataTypes.GeographyPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogLine", EdmDataTypes.GeographyLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogPolygon", EdmDataTypes.GeographyPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogCollection", EdmDataTypes.GeographyCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPoint", EdmDataTypes.GeographyMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiLine", EdmDataTypes.GeographyMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeogMultiPolygon", EdmDataTypes.GeographyMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Geom", EdmDataTypes.Geometry.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPoint", EdmDataTypes.GeometryPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomLine", EdmDataTypes.GeometryLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomPolygon", EdmDataTypes.GeometryPolygon.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomCollection", EdmDataTypes.GeometryCollection.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPoint", EdmDataTypes.GeometryMultiPoint.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiLine", EdmDataTypes.GeometryMultiLineString.WithSrid(SpatialConstants.VariableSrid)),
                    new MemberProperty("GeomMultiPolygon", EdmDataTypes.GeometryMultiPolygon.WithSrid(SpatialConstants.VariableSrid)),

                    new MemberProperty("Complex", DataTypes.ComplexType.WithName("AllSpatialTypesComplex")),
                },
                new EntityType("DVDCustomer")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", EdmDataTypes.String()),
                    new MemberProperty("EMail", EdmDataTypes.String()),
                    new MemberProperty("Visa", EdmDataTypes.Int32),
                    new MemberProperty("BalancePaid", EdmDataTypes.Boolean),
                    new NavigationProperty("DVDShipActivities", "DVDCustomer_DVDShipActivities", "DVDCustomer", "DVDShipActivity"),
                },
                new EntityType("DVDShipActivity")
                {
                    new MemberProperty("Id", EdmDataTypes.Int32)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("OrderDescription", EdmDataTypes.String()),
                    new MemberProperty("Title", EdmDataTypes.String()),
                    new MemberProperty("ShipTime", EdmDataTypes.DateTime()),
                    new MemberProperty("ReturnTime", EdmDataTypes.DateTime()),
                    new MemberProperty("ProblemReport", EdmDataTypes.String()),
                    new NavigationProperty("DVDCustomer", "DVDCustomer_DVDShipActivities", "DVDShipActivity", "DVDCustomer"),
                },
                new AssociationType("DVDCustomer_DVDShipActivities")
                {
                    new AssociationEnd("DVDCustomer", "DVDCustomer", EndMultiplicity.One),
                    new AssociationEnd("DVDShipActivity", "DVDShipActivity", EndMultiplicity.Many),
                },
                new AssociationType("Movies_Actors")
                {
                    new AssociationEnd("Movies", "Movie", EndMultiplicity.Many),
                    new AssociationEnd("Actors", "Actor", EndMultiplicity.Many),
                },
                new AssociationType("ActorMovieRating_Movie")
                {
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.ZeroOne),
                    new AssociationEnd("ActorMovieRating", "ActorMovieRating", EndMultiplicity.Many),
                },
                new AssociationType("ActorMovieRating_Actor")
                {
                    new AssociationEnd("Actor", "Actor", EndMultiplicity.ZeroOne),
                    new AssociationEnd("ActorMovieRating", "ActorMovieRating", EndMultiplicity.Many),
                },
                new AssociationType("MovieRating_Movie")
                {
                    new AssociationEnd("MovieRating", "MovieRating", EndMultiplicity.Many),
                    new AssociationEnd("Movie", "Movie", EndMultiplicity.ZeroOne),
                },
                new Function("CheckoutFirstMovie")
                {
                    new ToggleBoolPropertyValueActionAnnotation()
                    {
                        SourceEntitySet = "Movie", ToggleProperty = "IsAwardWinner"
                    },
                    new ServiceOperationAnnotation()
                    {
                        BindingKind = OperationParameterBindingKind.Never, IsAction = true
                    }
                },
                new Function("PayCustomerBalance")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "BalancePaid", ReturnProperty = "DVDShipActivities"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction      = true,
                            EntitySetPath = "customer/DVDShipActivities",
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("customer", DataTypes.EntityType.WithDefinition("DVDCustomer")),
                    },

                    ReturnType = DataTypes.CollectionOfEntities("DVDShipActivity"),
                },
                new Function("AddToQueue")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                new Function("UpVoteExecutiveProducer")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "Toggle", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("executiveProducer", DataTypes.EntityType.WithDefinition("ExecutiveProducer")),
                    },

                    ReturnType = EdmDataTypes.String()
                },
                new Function("UpVoteProducer")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "Toggle", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("producer", DataTypes.EntityType.WithDefinition("Producer")),
                    },

                    ReturnType = EdmDataTypes.String()
                },
                new Function("AddToQueue2")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue2", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction    = true,
                            BindingKind = OperationParameterBindingKind.Sometimes
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                new Function("AddToQueueThrowError")
                {
                    Annotations =
                    {
                        new ThrowDataServiceExceptionAnnotation()
                        {
                            ErrorStatusCode = 500, ErrorMessage = "Throwing error in AddToQueueThrowError function"
                        },
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie", DataTypes.EntityType.WithDefinition("Movie")),
                    },

                    ReturnType = EdmDataTypes.Int32
                },

                new Function("MultiParameterFunction")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "AddToQueueValue", ReturnProperty = "Id"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("movie",    DataTypes.EntityType.WithDefinition("Movie")),
                        new FunctionParameter("author",   EdmDataTypes.String()),
                        new FunctionParameter("comments", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.String())),
                    },

                    ReturnType = EdmDataTypes.Int32
                },
                //// Declaring an action in the Actor Entity that will have a name collision with the 'Age' property
                new Function("Age")
                {
                    Annotations =
                    {
                        new ToggleBoolPropertyValueActionAnnotation()
                        {
                            ToggleProperty = "IsAwardWinner", ReturnProperty = "FirstName"
                        },
                        new ServiceOperationAnnotation()
                        {
                            IsAction = true,
                        }
                    },

                    Parameters =
                    {
                        new FunctionParameter("actor", DataTypes.EntityType.WithDefinition("Actor")),
                    },

                    ReturnType = EdmDataTypes.String()
                }
            };

            this.AddServiceOperationsToModel(model);

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

            // add MEST scenarios in the model
            if (this.DataProviderSettings.SupportsMest)
            {
                EntityContainer ec = model.EntityContainers.Single();
                EntityType      customerEntityType            = ec.EntitySets.Single(es => es.Name == "DVDCustomer").EntityType;
                EntitySet       instantWatchCustomerEntitySet = new EntitySet("InstantWatchCustomer", customerEntityType);
                ec.Add(instantWatchCustomerEntitySet);

                EntityType activityEntityType            = ec.EntitySets.Single(es => es.Name == "DVDShipActivity").EntityType;
                EntitySet  instantWatchActivityEntitySet = new EntitySet("InstantWatchActivity", activityEntityType);
                ec.Add(instantWatchActivityEntitySet);

                AssociationType at = model.Associations.Single(a => a.Name == "DVDCustomer_DVDShipActivities");
                ec.Add(new AssociationSet("InstantWatchCustomer_InstantWatchActivities", at)
                {
                    Ends =
                    {
                        new AssociationSetEnd(at.Ends[0], instantWatchCustomerEntitySet),
                        new AssociationSetEnd(at.Ends[1], instantWatchActivityEntitySet),
                    }
                });
            }

            // Only add these actions if its not using the model for call order tests
            if (!this.AdaptModelForCallOrderTests)
            {
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "ActorMovieRating"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Actor"));
                this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllTypes"));

                if (this.DataProviderSettings.SupportsSpatial)
                {
                    this.AddEntityTypeDrivenToggleActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllSpatialTypes"));
                }

                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllTypes"), "Int32Property");

                if (this.DataProviderSettings.SupportsSpatial)
                {
                    this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "AllSpatialTypes"), "Int32Property");
                }

                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Actor"), "Age");
                this.AddIncrementIntegerPropertyActions(model, model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie"), "LengthInMinutes");
            }

            // Add page size = 1 for all exposed entity sets in the model
            var movieEntitySet = model.EntityContainers.First().EntitySets.Single(es => es.Name == "Movie");

            movieEntitySet.Annotations.Add(new PageSizeAnnotation()
            {
                PageSize = 1
            });

            this.SetupBindingParameterCollectionTypeAnnotation(model);

            if (this.RemoveHigherVersionModelFeaturesExceptActionWithMultiValue)
            {
                new AddDefaultContainerFixup().Fixup(model);
                new SetDefaultDataServiceConfigurationBehaviors()
                {
                    MaxProtocolVersion = DataServiceProtocolVersion.V4
                }.Fixup(model);

                var functionsToSave = model.Functions.Where(f => f.IsAction() && f.ReturnType != null && f.Parameters.Count > 0);
                var functionToSave  = functionsToSave.Where(f => f.Parameters.Any(p => p.DataType is CollectionDataType && !(((CollectionDataType)p.DataType).ElementDataType is EntityDataType))).ToArray().FirstOrDefault();
                new RemoveHigherVersionFeaturesFixup(DataServiceProtocolVersion.V4).Fixup(model);

                model.Add(functionToSave);
            }

            // Remove streams from the model if this is being used for call order tests
            if (this.AdaptModelForCallOrderTests)
            {
                new RemoveNamedStreamsFixup().Fixup(model);
                model.EntityTypes.ForEach(et => et.Annotations.RemoveAll(a => a.GetType() == typeof(HasStreamAnnotation)));

                // Add Query Interceptors for all sets so they will be triggered when running via call order
                model.EntityContainers.Single().EntitySets.ForEach(es => es.Annotations.Add(new ConstantInterceptorAnnotation()
                {
                    FilterConstant = true
                }));
            }

            return(model);
        }
Ejemplo n.º 3
0
        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);
        }
        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.InterestingValue <string>(string.Empty), DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                    new MemberProperty("PrimaryContactInfo", DataTypes.ComplexType.WithName("ContactDetails")),
                    new MemberProperty("BackupContactInfo", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithName("ContactDetails"))),
                    new MemberProperty("Auditing", DataTypes.ComplexType.WithName("AuditInfo")),
                    new MemberProperty("Thumbnail", DataTypes.Stream),
                    new MemberProperty("Video", DataTypes.Stream),
                    new MemberProperty("MembershipDuration", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    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("AlternativeNames", DataTypes.CollectionType.WithElementDataType(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("EmailBag", DataTypes.CollectionType.WithElementDataType(DataTypes.String.WithMaxLength(32))),
                    new MemberProperty("AlternativeNames", DataTypes.CollectionType.WithElementDataType(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("MobilePhoneBag", DataTypes.CollectionType.WithElementDataType(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), DataGenerationHints.MaxLength(30)),
                    new MemberProperty("Label", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.AnsiString, DataGenerationHints.MinLength(3)),
                },
                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("RSAToken")
                {
                    new MemberProperty("Serial", DataTypes.String.WithMaxLength(20))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Issued", DataTypes.DateTime),
                    new NavigationProperty("Login", "Login_RSAToken", "RSAToken", "Login"),
                },
                new EntityType("PageView")
                {
                    new MemberProperty("PageViewId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50)),
                    new MemberProperty("Viewed", DataTypes.DateTime.WithTimeZoneOffset(true)),
                    new MemberProperty("TimeSpentOnPage", DataTypes.TimeOfDay),
                    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 MemberProperty("ConcurrencyToken", DataTypes.String)
                        {
                            Annotations = { new ConcurrencyTokenAnnotation() }
                        },
                    }
                },
                new EntityType("LastLogin")
                {
                    new MemberProperty("Username", DataTypes.String.WithMaxLength(50))
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("LoggedIn", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                    new MemberProperty("LoggedOut", DataTypes.DateTime.WithTimeZoneOffset(true).NotNullable()),
                    new MemberProperty("Duration", DataTypes.TimeOfDay),
                    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.WithTimeZoneOffset(true)),
                    new MemberProperty("Subject", DataTypes.String.NotNullable()).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty)),
                    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("Login", "Login_Orders", "Orders", "Login"),
                },
                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 MemberProperty("OrderLineStream", DataTypes.Stream),
                    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 MemberProperty("Picture", DataTypes.Stream),
                    new NavigationProperty("RelatedProducts", "Products_RelatedProducts", "Product", "RelatedProducts"),
                    new NavigationProperty("Detail", "Product_ProductDetail", "Product", "ProductDetail"),
                    new NavigationProperty("Reviews", "Product_ProductReview", "Product", "ProductReview"),
                    new NavigationProperty("Photos", "Product_ProductPhoto", "Product", "ProductPhoto"),
                },
                new EntityType("DiscontinuedProduct")
                {
                    BaseType   = "Product",
                    Properties =
                    {
                        new MemberProperty("Discontinued",          DataTypes.DateTime),
                        new MemberProperty("ReplacementProductId",  DataTypes.Integer.Nullable()),
                        new MemberProperty("DiscontinuedPhone",     DataTypes.ComplexType.WithName("Phone")),
                        new MemberProperty("ChildConcurrencyToken", DataTypes.String)
                        {
                            Annotations = { new ConcurrencyTokenAnnotation() }
                        },
                    },
                },
                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 EntityType("ProductPhoto")
                {
                    new MemberProperty("ProductId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("PhotoId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Photo", DataTypes.Binary),
                },
                new EntityType("CustomerInfo")
                {
                    new MemberProperty("CustomerInfoId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Information", DataTypes.String.Nullable()),
                    new HasStreamAnnotation(),
                },
                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).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty)),
                    new MemberProperty("Model", DataTypes.String).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty)),
                    new MemberProperty("Serial", DataTypes.String),
                    new MemberProperty("SpecificationsBag", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                    new MemberProperty("PurchaseDate", DataTypes.DateTime),
                    new MemberProperty("Dimensions", DataTypes.ComplexType.WithName("Dimensions")),
                    new NavigationProperty("Computer", "Computer_ComputerDetail", "ComputerDetail", "Computer"),
                },
                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).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty)),
                    new MemberProperty("Restrictions", DataTypes.String).WithDataGenerationHints(DataGenerationHints.InterestingValue <string>(string.Empty)),
                    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("BagOfPrimitiveToLinks", DataTypes.CollectionType.WithElementDataType(DataTypes.String)),
                    new MemberProperty("Logo", DataTypes.Binary.WithMaxLength(500)),
                    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("BagOfInt64s", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Int64)),
                    new MemberProperty("BagOfGuids", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.Guid)),
                    new MemberProperty("BagOfDateTime", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())),
                    new MemberProperty("BagOfComplexToCategories", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithName("ComplexToCategory"))),
                    new MemberProperty("CollectionOfDateTimeOffset", DataTypes.CollectionType.WithElementDataType(DataTypes.DateTime.WithTimeZoneOffset(true))),
                    new MemberProperty("ComplexPhone", DataTypes.ComplexType.WithName("Phone")),
                    new MemberProperty("ComplexContactDetails", DataTypes.ComplexType.WithName("ContactDetails")),
                },
                new EntityType("Car")
                {
                    new MemberProperty("VIN", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Description", DataTypes.String.WithMaxLength(100).Nullable(true)),
                    new MemberProperty("Photo", DataTypes.Stream),
                    new MemberProperty("Video", DataTypes.Stream),
                    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("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("Login_Orders")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.ZeroOne),
                    new AssociationEnd("Orders", "Order", EndMultiplicity.Many),
                },
                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("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_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("Husband_Wife")
                {
                    new AssociationEnd("Husband", "Customer", EndMultiplicity.ZeroOne)
                    {
                        Annotations = { new PrincipalAnnotation() }
                    },
                    new AssociationEnd("Wife", "Customer", EndMultiplicity.ZeroOne),
                },
                new AssociationType("Login_RSAToken")
                {
                    new AssociationEnd("Login", "Login", EndMultiplicity.One),
                    new AssociationEnd("RSAToken", "RSAToken", EndMultiplicity.ZeroOne),
                },
                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"),
                },
                new EntityType("Person")
                {
                    new MemberProperty("PersonId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("Name", DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls, DataGenerationHints.MinLength(3)),
                    new NavigationProperty("PersonMetadata", "Person_PersonMetadata", "Person", "PersonMetadata"),
                },
                new EntityType("Employee")
                {
                    BaseType   = "Person",
                    Properties =
                    {
                        new MemberProperty("ManagersPersonId", DataTypes.Integer),
                        new MemberProperty("Salary",           DataTypes.Integer),
                        new MemberProperty("Title",            DataTypes.String).WithDataGenerationHints(DataGenerationHints.NoNulls,DataGenerationHints.MinLength(3)),
                    },
                    NavigationProperties =
                    {
                        new NavigationProperty("Manager", "Employee_Manager", "Employee", "Manager"),
                    },
                },
                new EntityType("SpecialEmployee")
                {
                    BaseType   = "Employee",
                    Properties =
                    {
                        new MemberProperty("CarsVIN",       DataTypes.Integer),
                        new MemberProperty("Bonus",         DataTypes.Integer),
                        new MemberProperty("IsFullyVested", DataTypes.Boolean),
                    },
                    NavigationProperties =
                    {
                        new NavigationProperty("Car", "SpecialEmployee_Car", "SpecialEmployee", "Car"),
                    }
                },
                new EntityType("PersonMetadata")
                {
                    new MemberProperty("PersonMetadataId", DataTypes.Integer)
                    {
                        IsPrimaryKey = true
                    },
                    new MemberProperty("PersonId", DataTypes.Integer),
                    new MemberProperty("PropertyName", DataTypes.String),
                    new MemberProperty("PropertyValue", DataTypes.String),
                    new NavigationProperty("Person", "Person_PersonMetadata", "PersonMetadata", "Person"),
                },
                new AssociationType("Person_PersonMetadata")
                {
                    new AssociationEnd("Person", "Person", EndMultiplicity.One),
                    new AssociationEnd("PersonMetadata", "PersonMetadata", EndMultiplicity.Many),
                    new ReferentialConstraint()
                    .WithDependentProperties("PersonMetadata", "PersonId")
                    .ReferencesPrincipalProperties("Person", "PersonId"),
                },
                new AssociationType("Employee_Manager")
                {
                    new AssociationEnd("Employee", "Employee", EndMultiplicity.Many),
                    new AssociationEnd("Manager", "Employee", EndMultiplicity.One),
                    new ReferentialConstraint()
                    .WithDependentProperties("Employee", "ManagersPersonId")
                    .ReferencesPrincipalProperties("Manager", "PersonId"),
                },
                new AssociationType("SpecialEmployee_Car")
                {
                    new AssociationEnd("SpecialEmployee", "SpecialEmployee", EndMultiplicity.Many),
                    new AssociationEnd("Car", "Car", EndMultiplicity.One),
                    new ReferentialConstraint()
                    .WithDependentProperties("SpecialEmployee", "CarsVIN")
                    .ReferencesPrincipalProperties("Car", "VIN"),
                },
                new Function("GetPrimitiveString")
                {
                    ReturnType  = EdmDataTypes.String().NotNullable(),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation
                        {
                            Method = HttpVerb.Get,
                        },
                        new FunctionBodyAnnotation
                        {
                            FunctionBody = CommonQueryBuilder.Constant("Foo"),
                        },
                    },
                },
                new Function("GetSpecificCustomer")
                {
                    ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.EntityType.WithName("Customer")),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation
                        {
                            Method = HttpVerb.Get,
                            ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IEnumerable,
                        },
                        new FunctionBodyAnnotation
                        {
                            FunctionBodyGenerator = (schema) =>
                            {
                                var entitySet = schema.GetDefaultEntityContainer().EntitySets.Where(set => set.Name.Equals("Customer")).Single();
                                return(CommonQueryBuilder.Root(entitySet).Where(c => c.Property("Name").EqualTo(CommonQueryBuilder.FunctionParameterReference("Name"))));
                            },
                        },
                    },
                    Parameters =
                    {
                        new FunctionParameter("Name", EdmDataTypes.String().NotNullable()),
                    },
                },
                new Function("GetCustomerCount")
                {
                    ReturnType  = EdmDataTypes.Int32.NotNullable(),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation
                        {
                            Method = HttpVerb.Get,
                        },
                        new FunctionBodyAnnotation
                        {
                            FunctionBodyGenerator = (schema) =>
                            {
                                var entitySet = schema.GetDefaultEntityContainer().EntitySets.Where(set => set.Name.Equals("Customer")).Single();
                                return(CommonQueryBuilder.Root(entitySet).Count());
                            },
                        },
                    },
                },
                new Function("GetArgumentPlusOne")
                {
                    ReturnType  = EdmDataTypes.Int32.NotNullable(),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation
                        {
                            Method = HttpVerb.Get,
                        },
                        new FunctionBodyAnnotation
                        {
                            FunctionBody = CommonQueryBuilder.Add(CommonQueryBuilder.FunctionParameterReference("arg1"), CommonQueryBuilder.Constant((int)1)),
                        },
                    },
                    Parameters =
                    {
                        new FunctionParameter("arg1", EdmDataTypes.Int32.NotNullable()),
                    },
                },
                new Function("EntityProjectionReturnsCollectionOfComplexTypes")
                {
                    ReturnType  = DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithName("ContactDetails")),
                    Annotations =
                    {
                        new LegacyServiceOperationAnnotation {
                            Method = HttpVerb.Get, ReturnTypeQualifier = ServiceOperationReturnTypeQualifier.IEnumerable,
                        },
                        new FunctionBodyAnnotation
                        {
                            FunctionBodyGenerator = (schema) =>
                            {
                                var entitySet = schema.GetDefaultEntityContainer().EntitySets.Where(set => set.Name.Equals("Customer")).Single();
                                return(CommonQueryBuilder.Root(entitySet).Select(e => e.Property("PrimaryContactInfo")));
                            },
                        },
                    },
                },
            };

            // TODO: Add more types for other features like relationship link, streams.
            if (this.RunStability == RunStability.Unstable)
            {
                // Add a service operation for each base entity type
                new AddRootServiceOperationsFixup().Fixup(model);

                // Add some WebInvoke service opeartions covering entity types with navigation, inheritance, concurrency
                this.AddWebInvokeServiceOperations(model);
            }

            // Apply default fixups
            new ResolveReferencesFixup().Fixup(model);
            new ApplyDefaultNamespaceFixup("DefaultNamespace").Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);
            return(model);
        }