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


C# Model.GetOrAddProperty方法代码示例

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


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

示例1: 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 = entityType.AddIndex(new[] { property1, property2 });
            index.IsUnique = true;

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

示例2: Can_create_index_from_properties

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

            var index = entityType.AddIndex(new[] { property1, property2 }, ConfigurationSource.Convention);

            Assert.True(new[] { property1, property2 }.SequenceEqual(index.Properties));
            Assert.False(index.IsUnique);
            Assert.Equal(ConfigurationSource.Convention, index.GetConfigurationSource());
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:12,代码来源:IndexTest.cs

示例3: 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);
            property2.IsNullable = false;

            var key = entityType.AddKey(new[] { property1, property2 }, ConfigurationSource.Convention);

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

示例4: 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(CoreStrings.KeyPropertiesWrongEntity($"{{'{property1.Name}', '{property2.Name}'}}", entityType1.DisplayName()),
                Assert.Throws<InvalidOperationException>(
                    () => entityType1.AddKey(new[] { property1, property2 })).Message);
        }
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:11,代码来源:KeyTest.cs


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