Example #1
0
        private static IModel BuildModel()
        {
            var model   = new Model();
            var builder = new BasicModelBuilder(model);

            builder.Annotation("ModelAnnotation1", "ModelValue1");
            builder.Annotation("ModelAnnotation2", "ModelValue2");

            var entityType1 = model.AddEntityType(typeof(KoolEntity1));
            var property    = entityType1.GetOrAddProperty("Id1", typeof(int));

            entityType1.GetOrSetPrimaryKey(property);
            entityType1.GetOrAddProperty("Id2", typeof(Guid));
            entityType1.GetOrAddProperty("KoolEntity2Id", typeof(int));

            var entityType2 = model.AddEntityType(typeof(KoolEntity2));

            entityType2.GetOrAddProperty("KoolEntity1Id1", typeof(int));
            entityType2.GetOrAddProperty("KoolEntity1Id2", typeof(Guid));
            entityType2.GetOrAddProperty("KoolEntity3Id", typeof(int));

            var entityType3 = model.AddEntityType(typeof(KoolEntity3));

            entityType3.GetOrAddProperty("KoolEntity4Id", typeof(int));

            var entityType4 = model.AddEntityType(typeof(KoolEntity4));

            var entityType5 = model.AddEntityType(typeof(KoolEntity5));

            var entityType6 = model.AddEntityType(typeof(KoolEntity6));

            entityType6.GetOrAddProperty("Kool5Id", typeof(int));

            for (var i = 7; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                Assert.NotNull(type);

                model.AddEntityType(type);
            }

            for (var i = 2; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);
                var id         = entityType.GetOrAddProperty(entityType.Type.GetProperty("Id"));
                entityType.GetOrSetPrimaryKey(id);
            }

            for (var i = 1; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);

                entityType["Annotation1"] = "Value1";
                entityType["Annotation2"] = "Value2";

                var foo = entityType.GetOrAddProperty(entityType.Type.GetProperty("Foo" + i));

                foo["Foo" + i + "Annotation1"] = "Foo" + i + "Value1";
                foo["Foo" + i + "Annotation2"] = "Foo" + i + "Value2";

                var goo = entityType.GetOrAddProperty(entityType.Type.GetProperty("Goo" + i));
            }

            var fk11 = entityType1.GetOrAddForeignKey(new[] { entityType1.GetProperty("KoolEntity2Id") }, entityType2.GetPrimaryKey());
            var fk21 = entityType2.GetOrAddForeignKey(new[] { entityType2.GetProperty("KoolEntity1Id1") }, entityType1.GetPrimaryKey());
            var fk22 = entityType2.GetOrAddForeignKey(new[] { entityType2.GetProperty("KoolEntity3Id") }, entityType3.GetPrimaryKey());
            var fk31 = entityType3.GetOrAddForeignKey(new[] { entityType3.GetProperty("KoolEntity4Id") }, entityType4.GetPrimaryKey());
            var fk61 = entityType6.GetOrAddForeignKey(new[] { entityType6.GetProperty("Kool5Id") }, entityType5.GetPrimaryKey());

            entityType1.AddNavigation("NavTo2", fk11, pointsToPrincipal: true);
            entityType1.AddNavigation("NavTo2s", fk21, pointsToPrincipal: false);
            entityType2.AddNavigation("NavTo1", fk21, pointsToPrincipal: true);
            entityType2.AddNavigation("NavTo1s", fk11, pointsToPrincipal: false);
            entityType2.AddNavigation("NavTo3", fk22, pointsToPrincipal: true);
            entityType3.AddNavigation("NavTo2s", fk22, pointsToPrincipal: false);
            entityType3.AddNavigation("NavTo4", fk31, pointsToPrincipal: true);
            entityType4.AddNavigation("NavTo3s", fk31, pointsToPrincipal: false);
            entityType5.AddNavigation("Kool6s", fk61, pointsToPrincipal: false);
            entityType6.AddNavigation("Kool5", fk61, pointsToPrincipal: true);

            return(model);
        }
        private static IModel BuildModel()
        {
            var model = new Model();
            var builder = new BasicModelBuilder(model);

            builder.Annotation("ModelAnnotation1", "ModelValue1");
            builder.Annotation("ModelAnnotation2", "ModelValue2");

            var entityType1 = model.AddEntityType(typeof(KoolEntity1));
            var property = entityType1.GetOrAddProperty("Id1", typeof(int));
            entityType1.GetOrSetPrimaryKey(property);
            entityType1.GetOrAddProperty("Id2", typeof(Guid));
            entityType1.GetOrAddProperty("KoolEntity2Id", typeof(int));

            var entityType2 = model.AddEntityType(typeof(KoolEntity2));
            entityType2.GetOrAddProperty("KoolEntity1Id1", typeof(int));
            entityType2.GetOrAddProperty("KoolEntity1Id2", typeof(Guid));
            entityType2.GetOrAddProperty("KoolEntity3Id", typeof(int));

            var entityType3 = model.AddEntityType(typeof(KoolEntity3));
            entityType3.GetOrAddProperty("KoolEntity4Id", typeof(int));

            var entityType4 = model.AddEntityType(typeof(KoolEntity4));

            var entityType5 = model.AddEntityType(typeof(KoolEntity5));

            var entityType6 = model.AddEntityType(typeof(KoolEntity6));
            entityType6.GetOrAddProperty("Kool5Id", typeof(int));

            for (var i = 7; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                Assert.NotNull(type);

                model.AddEntityType(type);
            }

            for (var i = 2; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);
                var id = entityType.GetOrAddProperty(entityType.ClrType.GetProperty("Id"));
                entityType.GetOrSetPrimaryKey(id);
            }

            for (var i = 1; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);

                entityType["Annotation1"] = "Value1";
                entityType["Annotation2"] = "Value2";

                var foo = entityType.GetOrAddProperty(entityType.ClrType.GetProperty("Foo" + i));

                foo["Foo" + i + "Annotation1"] = "Foo" + i + "Value1";
                foo["Foo" + i + "Annotation2"] = "Foo" + i + "Value2";

                var goo = entityType.GetOrAddProperty(entityType.ClrType.GetProperty("Goo" + i));
            }

            var fk11 = entityType1.GetOrAddForeignKey(new[] { entityType1.GetProperty("KoolEntity2Id") }, entityType2.GetPrimaryKey());
            var fk21 = entityType2.GetOrAddForeignKey(new[] { entityType2.GetProperty("KoolEntity1Id1") }, entityType1.GetPrimaryKey());
            var fk22 = entityType2.GetOrAddForeignKey(new[] { entityType2.GetProperty("KoolEntity3Id") }, entityType3.GetPrimaryKey());
            var fk31 = entityType3.GetOrAddForeignKey(new[] { entityType3.GetProperty("KoolEntity4Id") }, entityType4.GetPrimaryKey());
            var fk61 = entityType6.GetOrAddForeignKey(new[] { entityType6.GetProperty("Kool5Id") }, entityType5.GetPrimaryKey());

            entityType1.AddNavigation("NavTo2", fk11, pointsToPrincipal: true);
            entityType1.AddNavigation("NavTo2s", fk21, pointsToPrincipal: false);
            entityType2.AddNavigation("NavTo1", fk21, pointsToPrincipal: true);
            entityType2.AddNavigation("NavTo1s", fk11, pointsToPrincipal: false);
            entityType2.AddNavigation("NavTo3", fk22, pointsToPrincipal: true);
            entityType3.AddNavigation("NavTo2s", fk22, pointsToPrincipal: false);
            entityType3.AddNavigation("NavTo4", fk31, pointsToPrincipal: true);
            entityType4.AddNavigation("NavTo3s", fk31, pointsToPrincipal: false);
            entityType5.AddNavigation("Kool6s", fk61, pointsToPrincipal: false);
            entityType6.AddNavigation("Kool5", fk61, pointsToPrincipal: true);

            return model;
        }