本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}