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


C# EntityTypeConfiguration.Key方法代码示例

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


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

示例1: HasKey_composite_is_noop_when_set

        public void HasKey_composite_is_noop_when_set()
        {
            var type = new MockType()
                .Property<int>("Property1")
                .Property<int>("Property2")
                .Property<int>("Property3");
            var innerConfig = new EntityTypeConfiguration(type);
            innerConfig.Key(new[] { type.GetProperty("Property1") });
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasKey(new[] { "Property2", "Property3" });

            Assert.Equal(1, innerConfig.KeyProperties.Count());
            Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2"));
            Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property3"));
            Assert.Same(config, result);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:17,代码来源:LightweightEntityConfigurationTests.cs

示例2: Key_appends_key_members_when_not_set_by_attributes

        public void Key_appends_key_members_when_not_set_by_attributes()
        {
            var config = new EntityTypeConfiguration(typeof(AType1));

            config.Key(typeof(AType1).GetDeclaredProperty("Key1"));
            config.Key(typeof(AType1).GetDeclaredProperty("Key2"));

            Assert.Equal(2, config.KeyProperties.Count());
            Assert.Equal("Key1", config.KeyProperties.First().Name);
            Assert.Equal("Key2", config.KeyProperties.Last().Name);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:EntityTypeConfigurationTests.cs

示例3: HasKey_composite_is_noop_when_set

        public void HasKey_composite_is_noop_when_set()
        {
            var type = typeof(AType);
            var innerConfig = new EntityTypeConfiguration(type);
            innerConfig.Key(new[] { type.GetDeclaredProperty("Property1") });
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var result = config.HasKey(new[] { "Property2", "Property4" });

            Assert.Equal(1, innerConfig.KeyProperties.Count());
            Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2"));
            Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property4"));
            Assert.Same(config, result);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:14,代码来源:ConventionTypeConfigurationTests.cs

示例4: Configure_should_throw_when_key_properties_and_not_root_type

        public void Configure_should_throw_when_key_properties_and_not_root_type()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace)
                                 {
                                     BaseType = new EntityType("E", "N", DataSpace.CSpace)
                                 };
            var type = typeof(string);

            entityType.BaseType.GetMetadataProperties().SetClrType(type);
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            entityTypeConfiguration.Key(new MockPropertyInfo(typeof(int), "Id"));

            Assert.Equal(
                Strings.KeyRegisteredOnDerivedType(typeof(object), typeof(string)),
                Assert.Throws<InvalidOperationException>(
                    () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:17,代码来源:EntityTypeConfigurationTests.cs

示例5: Configure_should_throw_when_key_property_not_found

        public void Configure_should_throw_when_key_property_not_found()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id");
            entityTypeConfiguration.Key(mockPropertyInfo);

            Assert.Equal(
                Strings.KeyPropertyNotFound(("Id"), "E"),
                Assert.Throws<InvalidOperationException>(
                    () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:12,代码来源:EntityTypeConfigurationTests.cs

示例6: Configure_should_configure_and_order_keys_when_keys_and_order_specified

        public void Configure_should_configure_and_order_keys_when_keys_and_order_specified()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2");
            entityTypeConfiguration.Key(mockPropertyInfo2);
            entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1;
            (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2);
            var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1");
            entityTypeConfiguration.Key(mockPropertyInfo1);
            entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0;
            (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1);

            entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace));

            Assert.Equal(2, entityType.KeyProperties.Count);
            Assert.Equal("P1", entityType.KeyProperties.First().Name);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:25,代码来源:EntityTypeConfigurationTests.cs

示例7: IsKey_is_noop_when_set

        public void IsKey_is_noop_when_set()
        {
            var typeConfig = new EntityTypeConfiguration(typeof(AType2));
            typeConfig.Key(new[] { typeof(AType2).GetDeclaredProperty("Property1") });
            var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration
                {
                    TypeConfiguration = typeConfig
                };
            var propertyInfo = typeof(AType2).GetDeclaredProperty("Property2");
            var config = new ConventionPrimitivePropertyConfiguration(propertyInfo, () => innerConfig);

            var result = config.IsKey();

            Assert.DoesNotContain(propertyInfo, typeConfig.KeyProperties);
            Assert.Same(config, result);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:16,代码来源:ConventionPrimitivePropertyConfigurationTests.cs

示例8: IsKey_is_noop_when_set

        public void IsKey_is_noop_when_set()
        {
            var type = new MockType()
                .Property<int>("Property1")
                .Property<int>("Property2");
            var typeConfig = new EntityTypeConfiguration(type);
            typeConfig.Key(new[] { type.GetProperty("Property1") });
            var innerConfig = new PrimitivePropertyConfiguration
            {
                TypeConfiguration = typeConfig
            };
            var propertyInfo = type.GetProperty("Property2");
            var config = new LightweightPropertyConfiguration(propertyInfo, () => innerConfig);

            var result = config.IsKey();

            Assert.DoesNotContain(propertyInfo, typeConfig.KeyProperties);
            Assert.Same(config, result);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:19,代码来源:LightweightPropertyConfigurationTests.cs

示例9: Key_does_not_append_key_members_once_set_by_attributes

        public void Key_does_not_append_key_members_once_set_by_attributes()
        {
            var type = new MockType()
                .Property<int>("Key1")
                .Property<int>("Key2");
            var config = new EntityTypeConfiguration(type);

            config.Key(type.GetProperty("Key1"), null, true);
            config.Key(type.GetProperty("Key2"));

            Assert.Equal(1, config.KeyProperties.Count());
            Assert.Equal("Key1", config.KeyProperties.Single().Name);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:13,代码来源:EntityTypeConfigurationTests.cs

示例10: Key_appends_key_members_when_not_set_by_attributes

        public void Key_appends_key_members_when_not_set_by_attributes()
        {
            var type = new MockType()
                .Property<int>("Key1")
                .Property<int>("Key2");
            var config = new EntityTypeConfiguration(type);

            config.Key(type.GetProperty("Key1"));
            config.Key(type.GetProperty("Key2"));

            Assert.Equal(2, config.KeyProperties.Count());
            Assert.Equal("Key1", config.KeyProperties.First().Name);
            Assert.Equal("Key2", config.KeyProperties.Last().Name);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:14,代码来源:EntityTypeConfigurationTests.cs


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