本文整理汇总了C#中EntityType.GetPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetPrimaryKey方法的具体用法?C# EntityType.GetPrimaryKey怎么用?C# EntityType.GetPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.GetPrimaryKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_get_set_reset_and_clear_primary_key
public void Can_get_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.GetOrSetPrimaryKey(new[] { idProperty, nameProperty });
Assert.NotNull(key1);
Assert.Same(key1, entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty }));
Assert.Same(key1, entityType.GetPrimaryKey());
Assert.Same(key1, entityType.FindPrimaryKey());
Assert.Same(key1, entityType.Keys.Single());
var key2 = entityType.GetOrSetPrimaryKey(idProperty);
Assert.NotNull(key2);
Assert.NotEqual(key1, key2);
Assert.Same(key2, entityType.GetOrSetPrimaryKey(idProperty));
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.GetOrSetPrimaryKey((Property)null));
Assert.Null(entityType.FindPrimaryKey());
Assert.Equal(2, entityType.Keys.Count);
Assert.Null(entityType.GetOrSetPrimaryKey(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);
}
示例2: FK_properties_are_marked_as_requiring_original_values
public void FK_properties_are_marked_as_requiring_original_values()
{
var entityType = new EntityType(typeof(FullNotificationEntity), new Model());
entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int)));
Assert.Equal(-1, entityType.GetProperty("Id").GetOriginalValueIndex());
entityType.GetOrAddForeignKey(new[] { entityType.GetOrAddProperty("Id", typeof(int)) }, entityType.GetPrimaryKey());
Assert.Equal(0, entityType.GetProperty("Id").GetOriginalValueIndex());
}