本文整理汇总了C#中EntityType.SetPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.SetPrimaryKey方法的具体用法?C# EntityType.SetPrimaryKey怎么用?C# EntityType.SetPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.SetPrimaryKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPrimaryKey
public void SetPrimaryKey(EntityType entityType)
{
var property = entityType.AddProperty("Id", typeof(int));
property.IsShadowProperty = false;
entityType.SetPrimaryKey(property);
}
示例2: Setting_primary_key_throws_if_properties_from_different_type
public void Setting_primary_key_throws_if_properties_from_different_type()
{
var entityType1 = new EntityType(typeof(Customer), new Model());
var entityType2 = new EntityType(typeof(Order), new Model());
var idProperty = entityType2.GetOrAddProperty(Customer.IdProperty);
Assert.Equal(
Strings.KeyPropertiesWrongEntity("{'" + Customer.IdProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<ArgumentException>(() => entityType1.SetPrimaryKey(idProperty)).Message);
}
示例3: Can_set_reset_and_clear_primary_key
public void Can_set_reset_and_clear_primary_key()
{
var entityType = new EntityType(typeof(Customer), new Model());
var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);
var key1 = entityType.SetPrimaryKey(new[] { idProperty, nameProperty });
Assert.NotNull(key1);
Assert.Same(key1, entityType.GetPrimaryKey());
Assert.Same(key1, entityType.FindPrimaryKey());
Assert.Same(key1, entityType.Keys.Single());
var key2 = entityType.SetPrimaryKey(idProperty);
Assert.NotNull(key2);
Assert.Same(key2, entityType.GetPrimaryKey());
Assert.Same(key2, entityType.FindPrimaryKey());
Assert.Equal(2, entityType.Keys.Count);
Assert.Same(key1, entityType.GetKey(key1.Properties));
Assert.Same(key2, entityType.GetKey(key2.Properties));
Assert.Null(entityType.SetPrimaryKey((Property)null));
Assert.Null(entityType.FindPrimaryKey());
Assert.Equal(2, entityType.Keys.Count);
Assert.Null(entityType.SetPrimaryKey(new Property[0]));
Assert.Null(entityType.FindPrimaryKey());
Assert.Equal(2, entityType.Keys.Count);
Assert.Equal(
Strings.EntityRequiresKey(typeof(Customer).FullName),
Assert.Throws<ModelItemNotFoundException>(() => entityType.GetPrimaryKey()).Message);
}
示例4: Properties_are_properly_ordered_when_primary_key_changes
public void Properties_are_properly_ordered_when_primary_key_changes()
{
var entityType = new EntityType(typeof(Customer), new Model());
var aProperty = entityType.AddProperty("A", typeof(int), true);
var bProperty = entityType.AddProperty("B", typeof(int), true);
entityType.SetPrimaryKey(bProperty);
Assert.True(new[] { bProperty, aProperty }.SequenceEqual(entityType.Properties));
entityType.SetPrimaryKey(aProperty);
Assert.True(new[] { aProperty, bProperty }.SequenceEqual(entityType.Properties));
}
示例5: Composite_primary_key_properties_are_listed_in_key_order
public void Composite_primary_key_properties_are_listed_in_key_order()
{
var entityType = new EntityType("CompositeKeyType", new Model());
var aProperty = entityType.AddProperty("A", typeof(int), true);
var pkProperty2 = entityType.AddProperty("aPK", typeof(int), true);
var pkProperty1 = entityType.AddProperty("bPK", typeof(int), true);
entityType.SetPrimaryKey(new[] { pkProperty1, pkProperty2 });
Assert.True(new[] { pkProperty1, pkProperty2, aProperty }.SequenceEqual(entityType.Properties));
}
示例6: Primary_key_properties_precede_others
public void Primary_key_properties_precede_others()
{
var entityType = new EntityType(typeof(Customer), new Model());
var aProperty = entityType.AddProperty("A", typeof(int), true);
var pkProperty = entityType.AddProperty(Customer.IdProperty);
entityType.SetPrimaryKey(pkProperty);
Assert.True(new[] { pkProperty, aProperty }.SequenceEqual(entityType.Properties));
}