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


C# Model.GetOrAddProperty方法代码示例

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


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

示例1: Can_create_key_from_properties

        public void Can_create_key_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            var key = new Key(new[] { property1, property2 });

            Assert.True(new[] { property1, property2 }.SequenceEqual(key.Properties));
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:10,代码来源:KeyTest.cs

示例2: Can_create_unique_index_from_properties

        public void Can_create_unique_index_from_properties()
        {
            var entityType = new Model().AddEntityType(typeof(Customer));
            var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType.GetOrAddProperty(Customer.NameProperty);

            var index = new Index(new[] { property1, property2 }) { IsUnique = true };

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.True(index.IsUnique.Value);
        }
开发者ID:491134648,项目名称:EntityFramework,代码行数:11,代码来源:IndexTest.cs

示例3: Principal_and_depedent_property_count_must_match

        public void Principal_and_depedent_property_count_must_match()
        {
            var dependentType = new Model().AddEntityType("D");
            var principalType = new Model().AddEntityType("P");

            var dependentProperty1 = dependentType.GetOrAddProperty("P1", typeof(int), shadowProperty: true);
            var dependentProperty2 = dependentType.GetOrAddProperty("P2", typeof(int), shadowProperty: true);

            principalType.GetOrSetPrimaryKey(principalType.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            Assert.Equal(
                Strings.ForeignKeyCountMismatch("{'P1', 'P2'}", "D", "{'Id'}", "P"),
                Assert.Throws<InvalidOperationException>(
                    () => new ForeignKey(new[] { dependentProperty1, dependentProperty2 }, principalType.GetPrimaryKey())).Message);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:15,代码来源:ForeignKeyTest.cs

示例4: Can_create_foreign_key

        public void Can_create_foreign_key()
        {
            var entityType = new Model().AddEntityType("E");
            var dependentProp = entityType.GetOrAddProperty("P", typeof(int), shadowProperty: true);
            var principalProp = entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true);
            entityType.GetOrSetPrimaryKey(principalProp);

            var foreignKey
                = new ForeignKey(new[] { dependentProp }, entityType.GetPrimaryKey())
                    {
                        IsUnique = true
                    };

            Assert.Same(entityType, foreignKey.PrincipalEntityType);
            Assert.Same(principalProp, foreignKey.PrincipalKey.Properties.Single());
            Assert.Same(dependentProp, foreignKey.Properties.Single());
            Assert.True(foreignKey.IsUnique.Value);
            Assert.Same(entityType.GetPrimaryKey(), foreignKey.PrincipalKey);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:19,代码来源:ForeignKeyTest.cs

示例5: Validates_properties_from_same_entity

        public void Validates_properties_from_same_entity()
        {
            var entityType1 = new Model().AddEntityType(typeof(Customer));
            var entityType2 = new Model().AddEntityType(typeof(Order));
            var property1 = entityType1.GetOrAddProperty(Customer.IdProperty);
            var property2 = entityType2.GetOrAddProperty(Order.NameProperty);

            Assert.Equal(Strings.InconsistentEntityType("properties"),
                Assert.Throws<ArgumentException>(
                    () => new Key(new[] { property1, property2 })).Message);
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:11,代码来源:KeyTest.cs

示例6: CreateProperty

        private static Property CreateProperty()
        {
            var entityType = new Model().AddEntityType("MyType");
            var property = entityType.GetOrAddProperty("MyProperty", typeof(string), shadowProperty: true);
            entityType.SqlServer().Table = "MyTable";

            return property;
        }
开发者ID:thegido,项目名称:EntityFramework,代码行数:8,代码来源:SqlServerValueGeneratorCacheTest.cs

示例7: CreateProperty

 private static Property CreateProperty()
 {
     var entityType = new Model().AddEntityType("Led");
     return entityType.GetOrAddProperty("Zeppelin", typeof(Guid), shadowProperty: true);
 }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:5,代码来源:ValueGeneratorFactoryTest.cs

示例8: CreateSelfRefFK

        private ForeignKey CreateSelfRefFK()
        {
            var entityType = new Model().AddEntityType(typeof(SelfRef));
            var pk = entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int)));
            var fkProp = entityType.GetOrAddProperty("SelfRefId", typeof(int?));

            var fk = entityType.AddForeignKey(new[] { fkProp }, pk);
            fk.IsUnique = true;
            entityType.AddNavigation("SelfRefPrincipal", fk, pointsToPrincipal: true);
            entityType.AddNavigation("SelfRefDependent", fk, pointsToPrincipal: false);
            return fk;
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:12,代码来源:ForeignKeyTest.cs

示例9: CreateOneToManyFK

        private ForeignKey CreateOneToManyFK()
        {
            var principalEntityType = new Model().AddEntityType(typeof(OneToManyPrincipal));
            var pk = principalEntityType.GetOrSetPrimaryKey(principalEntityType.GetOrAddProperty("Id", typeof(int)));

            var dependentEntityType = new Model().AddEntityType(typeof(OneToManyDependent));
            var fkProp = dependentEntityType.GetOrAddProperty("Id", typeof(int));
            return dependentEntityType.AddForeignKey(new[] { fkProp }, pk);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:9,代码来源:ForeignKeyTest.cs

示例10: Setting_IsRequired_to_false_will_set_all_FK_properties_as_nullable

        public void Setting_IsRequired_to_false_will_set_all_FK_properties_as_nullable()
        {
            var entityType = new Model().AddEntityType("E");
            entityType.GetOrSetPrimaryKey(new[]
                {
                    entityType.GetOrAddProperty("Id1", typeof(int), shadowProperty: true),
                    entityType.GetOrAddProperty("Id2", typeof(string), shadowProperty: true)
                });

            var dependentProp1 = entityType.GetOrAddProperty("P1", typeof(int?), shadowProperty: true);
            var dependentProp2 = entityType.GetOrAddProperty("P2", typeof(string), shadowProperty: true);

            var foreignKey = new ForeignKey(new[] { dependentProp1, dependentProp2 }, entityType.GetPrimaryKey()) { IsRequired = false };

            Assert.False(foreignKey.IsRequired.Value);
            Assert.True(dependentProp1.IsNullable.Value);
            Assert.True(dependentProp2.IsNullable.Value);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:18,代码来源:ForeignKeyTest.cs

示例11: IsRequired_false_when_any_part_of_composite_FK_is_nullable

        public void IsRequired_false_when_any_part_of_composite_FK_is_nullable()
        {
            var entityType = new Model().AddEntityType("E");
            entityType.GetOrSetPrimaryKey(new[]
                {
                    entityType.GetOrAddProperty("Id1", typeof(int), shadowProperty: true),
                    entityType.GetOrAddProperty("Id2", typeof(string), shadowProperty: true)
                });

            var dependentProp1 = entityType.GetOrAddProperty("P1", typeof(int), shadowProperty: true);
            var dependentProp2 = entityType.GetOrAddProperty("P2", typeof(string), shadowProperty: true);
            dependentProp2.IsNullable = true;

            var foreignKey = new ForeignKey(new[] { dependentProp1, dependentProp2 }, entityType.GetPrimaryKey());

            Assert.Null(foreignKey.IsRequired);
            Assert.False(((IForeignKey)foreignKey).IsRequired);

            dependentProp2.IsNullable = false;

            Assert.Null(foreignKey.IsRequired);
            Assert.True(((IForeignKey)foreignKey).IsRequired);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:23,代码来源:ForeignKeyTest.cs

示例12: IsRequired_false_for_composite_FK_by_default

        public void IsRequired_false_for_composite_FK_by_default()
        {
            var entityType = new Model().AddEntityType("E");
            entityType.GetOrSetPrimaryKey(new[]
                {
                    entityType.GetOrAddProperty("Id1", typeof(int), shadowProperty: true),
                    entityType.GetOrAddProperty("Id2", typeof(string), shadowProperty: true)
                });

            var dependentProp1 = entityType.GetOrAddProperty("P1", typeof(int), shadowProperty: true);
            var dependentProp2 = entityType.GetOrAddProperty("P2", typeof(string), shadowProperty: true);

            var foreignKey = new ForeignKey(new[] { dependentProp1, dependentProp2 }, entityType.GetPrimaryKey());

            Assert.Null(foreignKey.IsRequired);
            Assert.False(((IForeignKey)foreignKey).IsRequired);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:17,代码来源:ForeignKeyTest.cs

示例13: IsRequired_and_IsUnique_null_when_dependent_property_nullable_by_default

        public void IsRequired_and_IsUnique_null_when_dependent_property_nullable_by_default()
        {
            var entityType = new Model().AddEntityType("E");
            entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true));
            var dependentProp = entityType.GetOrAddProperty("P", typeof(int?), shadowProperty: true);

            var foreignKey = new ForeignKey(new[] { dependentProp }, entityType.GetPrimaryKey());

            Assert.Null(foreignKey.IsRequired);
            Assert.False(((IForeignKey)foreignKey).IsRequired);
            Assert.Null(foreignKey.IsUnique);
            Assert.False(((IForeignKey)foreignKey).IsUnique);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:13,代码来源:ForeignKeyTest.cs

示例14: IsRequired_true_when_dependent_property_not_nullable

        public void IsRequired_true_when_dependent_property_not_nullable()
        {
            var entityType = new Model().AddEntityType("E");
            entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true));
            var dependentProp = entityType.GetOrAddProperty("P", typeof(int), shadowProperty: true);
            dependentProp.IsNullable = false;

            var foreignKey = new ForeignKey(new[] { dependentProp }, entityType.GetPrimaryKey());

            Assert.Null(foreignKey.IsRequired);
            Assert.True(((IForeignKey)foreignKey).IsRequired);
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:12,代码来源:ForeignKeyTest.cs


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