本文整理汇总了C#中EntityTypeConfiguration.Key方法的典型用法代码示例。如果您正苦于以下问题:C# EntityTypeConfiguration.Key方法的具体用法?C# EntityTypeConfiguration.Key怎么用?C# EntityTypeConfiguration.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityTypeConfiguration
的用法示例。
在下文中一共展示了EntityTypeConfiguration.Key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure_should_throw_when_key_property_not_found
public void Configure_should_throw_when_key_property_not_found()
{
var entityType = new EntityType
{
Name = "E"
};
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())).Message);
}
示例2: 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
{
Name = "E"
};
var property = EdmProperty.Primitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property);
var property1 = EdmProperty.Primitive("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());
Assert.Equal(2, entityType.DeclaredKeyProperties.Count);
Assert.Equal("P1", entityType.DeclaredKeyProperties.First().Name);
}
示例3: 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
{
Name = "E",
BaseType = new EntityType()
};
var type = typeof(string);
var tempQualifier = entityType.BaseType;
tempQualifier.Annotations.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())).Message);
}
示例4: 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 EdmEntityType { Name = "E" };
entityType.AddPrimitiveProperty("P2").PropertyType.EdmType = EdmPrimitiveType.Int32;
entityType.AddPrimitiveProperty("P1").PropertyType.EdmType = EdmPrimitiveType.Int32;
var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2");
entityTypeConfiguration.Key(mockPropertyInfo2);
entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1;
entityType.GetDeclaredPrimitiveProperty("P2").SetClrPropertyInfo(mockPropertyInfo2);
var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1");
entityTypeConfiguration.Key(mockPropertyInfo1);
entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0;
entityType.GetDeclaredPrimitiveProperty("P1").SetClrPropertyInfo(mockPropertyInfo1);
entityTypeConfiguration.Configure(entityType, new EdmModel());
Assert.Equal(2, entityType.DeclaredKeyProperties.Count);
Assert.Equal("P1", entityType.DeclaredKeyProperties.First().Name);
}