当前位置: 首页>>代码示例>>C#>>正文


C# Model.AddEntityType方法代码示例

本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model.AddEntityType方法的典型用法代码示例。如果您正苦于以下问题:C# Model.AddEntityType方法的具体用法?C# Model.AddEntityType怎么用?C# Model.AddEntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Data.Entity.Metadata.Model的用法示例。


在下文中一共展示了Model.AddEntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Circular_inheritance_should_throw

        public void Circular_inheritance_should_throw()
        {
            var model = new Model();

            //    A
            //   / \
            //  B   C
            //       \
            //        D

            var a = model.AddEntityType(typeof(A).Name);
            var b = model.AddEntityType(typeof(B).Name);
            var c = model.AddEntityType(typeof(C).Name);
            var d = model.AddEntityType(typeof(D).Name);

            b.BaseType = a;
            c.BaseType = a;
            d.BaseType = c;

            Assert.Equal(
                Strings.CircularInheritance(a, a),
                Assert.Throws<InvalidOperationException>(() => a.BaseType = a).Message);

            Assert.Equal(
                Strings.CircularInheritance(a, b),
                Assert.Throws<InvalidOperationException>(() => a.BaseType = b).Message);

            Assert.Equal(
                Strings.CircularInheritance(a, d),
                Assert.Throws<InvalidOperationException>(() => a.BaseType = d).Message);
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:31,代码来源:EntityTypeTest.cs

示例2: Detects_foreign_key_cycles

        public virtual void Detects_foreign_key_cycles()
        {
            var model = new Model();
            var entityA = model.AddEntityType(typeof(A));
            var keyA = CreateKey(entityA);
            var entityB = model.AddEntityType(typeof(B));
            var keyB = CreateKey(entityB);

            CreateForeignKey(keyA, keyB);
            CreateForeignKey(keyB, keyA);
            
            VerifyError(Strings.CircularDependency("'A' {'P0'} -> 'B' {'P0'}, 'B' {'P0'} -> 'A' {'P0'}"), model);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:13,代码来源:ModelValidatorTest.cs

示例3: Throws_when_referenced_key_not_on_referenced_entity

        public void Throws_when_referenced_key_not_on_referenced_entity()
        {
            var model = new Model();

            var principalEntityType = model.AddEntityType("R");
            var dependentEntityType = model.AddEntityType("D");
            var fk = dependentEntityType.AddProperty("Fk", typeof(int), shadowProperty: true);

            var principalKey = dependentEntityType.SetPrimaryKey(fk);

            Assert.Throws<ArgumentException>(() =>
                new ForeignKey(new[] { fk }, principalKey, principalEntityType));
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:13,代码来源:ForeignKeyTest.cs

示例4: Passes_on_escapable_foreign_key_cycles_not_starting_at_hub

        public virtual void Passes_on_escapable_foreign_key_cycles_not_starting_at_hub()
        {
            var model = new Model();
            var entityA = model.AddEntityType(typeof(A));
            var keyA1 = CreateKey(entityA);
            var keyA2 = CreateKey(entityA, startingPropertyIndex: 1, propertyCount: 2);
            var entityB = model.AddEntityType(typeof(B));
            var keyB1 = CreateKey(entityB);
            var keyB2 = CreateKey(entityB, startingPropertyIndex: 0, propertyCount: 2);

            CreateForeignKey(keyA1, keyB1);
            CreateForeignKey(keyB1, keyA1);
            CreateForeignKey(keyB2, keyA2);

            Validate(model);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:16,代码来源:ModelValidatorTest.cs

示例5: Detects_shadow_entities

        public virtual void Detects_shadow_entities()
        {
            var model = new Model();
            model.AddEntityType("A");

            VerifyError(CoreStrings.ShadowEntity("A"), model);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:7,代码来源:ModelValidatorTest.cs

示例6: Properties_on_base_type_should_be_inherited

        public void Properties_on_base_type_should_be_inherited()
        {
            var model = new Model();

            //    A
            //   / \
            //  B   C

            var a = model.AddEntityType(typeof(A));
            a.AddProperty("G", typeof(string));
            a.AddProperty("E", typeof(string));

            var b = model.AddEntityType(typeof(B));
            b.AddProperty("H", typeof(string));
            b.AddProperty("F", typeof(string));

            var c = model.AddEntityType(typeof(C));
            c.AddProperty("H", typeof(string), true);
            c.AddProperty("I", typeof(string), true);

            Assert.Equal(new[] { "E", "G" }, a.Properties.Select(p => p.Name).ToArray());
            Assert.Equal(new[] { "F", "H" }, b.Properties.Select(p => p.Name).ToArray());
            Assert.Equal(new[] { "H", "I" }, c.Properties.Select(p => p.Name).ToArray());

            b.BaseType = a;
            c.BaseType = a;

            Assert.Equal(new[] { "E", "G" }, a.Properties.Select(p => p.Name).ToArray());
            Assert.Equal(new[] { "E", "G", "F", "H" }, b.Properties.Select(p => p.Name).ToArray());
            Assert.Equal(new[] { "E", "G", "H", "I" }, c.Properties.Select(p => p.Name).ToArray());
            Assert.Equal(new[] { 0, 1, 2, 3 }, b.Properties.Select(p => p.Index));
            Assert.Equal(new[] { 0, 1, 2, 3 }, c.Properties.Select(p => p.Index));
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:33,代码来源:EntityTypeTest.cs

示例7: CreateForeignKey

 private ForeignKey CreateForeignKey()
 {
     var model = new Model();
     var entityType = model.AddEntityType("E");
     var property = entityType.AddProperty("p", typeof(int), shadowProperty: true);
     var key = entityType.SetPrimaryKey(property);
     return new ForeignKey(new[] { property }, key);
 }
开发者ID:thegido,项目名称:EntityFramework,代码行数:8,代码来源:NavigationTest.cs

示例8: Detects_a_null_primary_key

        public virtual void Detects_a_null_primary_key()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("Id", typeof(int));

            VerifyError(CoreStrings.EntityRequiresKey(typeof(A).FullName), model);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:8,代码来源:ModelValidatorTest.cs

示例9: Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type

        public virtual void Detects_a_non_shadow_property_that_doesnt_match_the_CLR_property_type()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("P0", typeof(string));
            property.IsShadowProperty = false;

            VerifyError(Strings.PropertyWrongClrType("P0", typeof(A).FullName), model);
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:9,代码来源:ModelValidatorTest.cs

示例10: Detects_shadow_keys

        public virtual void Detects_shadow_keys()
        {
            var model = new Model();
            var entityType = model.AddEntityType("E");
            var keyProperty = entityType.AddProperty("Id", typeof(int), shadowProperty: true);
            entityType.AddKey(keyProperty);

            VerifyWarning(Strings.ShadowKey("{'Id'}", "E", "{'Id'}"), model);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:9,代码来源:ModelValidatorTest.cs

示例11: CreateForeignKey

 private ForeignKey CreateForeignKey()
 {
     var model = new Model();
     var entityType = model.AddEntityType("E");
     var idProperty = entityType.AddProperty("id", typeof(int));
     var key = entityType.SetPrimaryKey(idProperty);
     var fkProperty = entityType.AddProperty("p", typeof(int));
     return entityType.AddForeignKey(fkProperty, key, entityType);
 }
开发者ID:491134648,项目名称:EntityFramework,代码行数:9,代码来源:NavigationTest.cs

示例12: CreateModel

        private static Model CreateModel(bool generateValues = true)
        {
            var model = new Model();

            var entityType = model.AddEntityType("Led");
            entityType.AddProperty("Zeppelin", typeof(Guid));
            entityType.AddProperty("Stairway", typeof(Guid)).RequiresValueGenerator = generateValues;

            return model;
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:10,代码来源:ValueGeneratorCacheTest.cs

示例13: BuildModel

        protected override Model BuildModel()
        {
            var model = new Model();

            var entityType1 = new EntityType("SomeEntity");
            model.AddEntityType(entityType1);
            var key1 = entityType1.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
            key1.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
            key1.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
            entityType1.SetKey(key1);
            entityType1.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);

            var entityType2 = new EntityType("SomeDependentEntity");
            model.AddEntityType(entityType2);
            var key2a = entityType2.AddProperty("Id1", typeof(int), shadowProperty: true, concurrencyToken: false);
            var key2b = entityType2.AddProperty("Id2", typeof(string), shadowProperty: true, concurrencyToken: false);
            entityType2.SetKey(key2a, key2b);
            var fk = entityType2.AddProperty("SomeEntityId", typeof(int), shadowProperty: true, concurrencyToken: false);
            entityType2.AddForeignKey(entityType1.GetKey(), new[] { fk });
            var justAProperty = entityType2.AddProperty("JustAProperty", typeof(int), shadowProperty: true, concurrencyToken: false);
            justAProperty.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
            justAProperty.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;

            var entityType3 = new EntityType(typeof(FullNotificationEntity));
            model.AddEntityType(entityType3);
            entityType3.SetKey(entityType3.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
            entityType3.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);

            var entityType4 = new EntityType(typeof(ChangedOnlyEntity));
            model.AddEntityType(entityType4);
            entityType4.SetKey(entityType4.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
            entityType4.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);

            var entityType5 = new EntityType("SomeMoreDependentEntity");
            model.AddEntityType(entityType5);
            var key5 = entityType5.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
            entityType5.SetKey(key5);
            var fk5a = entityType5.AddProperty("Fk1", typeof(int), shadowProperty: true, concurrencyToken: false);
            var fk5b = entityType5.AddProperty("Fk2", typeof(string), shadowProperty: true, concurrencyToken: false);
            entityType5.AddForeignKey(entityType2.GetKey(), new[] { fk5a, fk5b });

            return model;
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:43,代码来源:ShadowStateEntryTest.cs

示例14: Detects_a_non_shadow_property_that_doesnt_match_a_CLR_property

        public virtual void Detects_a_non_shadow_property_that_doesnt_match_a_CLR_property()
        {
            var model = new Model();
            var entityType = model.AddEntityType(typeof(A));
            var property = entityType.AddProperty("Id1", typeof(int));
            property.IsShadowProperty = false;
            entityType.SetPrimaryKey(property);

            VerifyError(CoreStrings.NoClrProperty("Id1", typeof(A).FullName), model);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:10,代码来源:ModelValidatorTest.cs

示例15: Detects_self_referencing_properties

        public virtual void Detects_self_referencing_properties()
        {
            var model = new Model();
            var entityA = model.AddEntityType(typeof(A));
            var keyA = CreateKey(entityA);

            CreateForeignKey(keyA, keyA);

            VerifyError(Strings.CircularDependency("'A' {'P0'} -> 'A' {'P0'}"), model);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:10,代码来源:ModelValidatorTest.cs


注:本文中的Microsoft.Data.Entity.Metadata.Model.AddEntityType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。