本文整理汇总了C#中EntityType.GetOrSetPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetOrSetPrimaryKey方法的具体用法?C# EntityType.GetOrSetPrimaryKey怎么用?C# EntityType.GetOrSetPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.GetOrSetPrimaryKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_remove_keys
public void Can_remove_keys()
{
var entityType = new EntityType(typeof(Customer), new Model());
var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);
Assert.Equal(
Strings.KeyNotFound("{'" + idProperty.Name + "', '" + nameProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<ModelItemNotFoundException>(() => entityType.GetKey(new[] { idProperty, nameProperty })).Message);
Assert.Null(entityType.RemoveKey(new Key(new[] { idProperty })));
var key1 = entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty });
var key2 = entityType.GetOrAddKey(idProperty);
Assert.Equal(new[] { key2, key1 }, entityType.Keys.ToArray());
Assert.Same(key1, entityType.RemoveKey(key1));
Assert.Null(entityType.RemoveKey(key1));
Assert.Equal(
Strings.KeyNotFound("{'" + idProperty.Name + "', '" + nameProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<ModelItemNotFoundException>(() => entityType.GetKey(new[] { idProperty, nameProperty })).Message);
Assert.Equal(new[] { key2 }, entityType.Keys.ToArray());
Assert.Same(key2, entityType.RemoveKey(new Key(new[] { idProperty })));
Assert.Empty(entityType.Keys);
}
示例2: Adding_a_key_throws_if_same_as_primary
public void Adding_a_key_throws_if_same_as_primary()
{
var entityType = new EntityType(typeof(Customer), new Model());
var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);
entityType.GetOrSetPrimaryKey(new[] { idProperty, nameProperty });
Assert.Equal(
Strings.DuplicateKey("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(() => entityType.AddKey(new[] { idProperty, nameProperty })).Message);
}
示例3: 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);
}
示例4: 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());
}
示例5: Cannot_remove_property_when_used_by_foreign_key
public void Cannot_remove_property_when_used_by_foreign_key()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerPk = customerType.GetOrSetPrimaryKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var customerFk = orderType.GetOrAddProperty(Order.CustomerIdProperty);
orderType.GetOrAddForeignKey(customerFk, customerPk);
Assert.Equal(
Strings.PropertyInUse("CustomerId", typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(() => orderType.RemoveProperty(customerFk)).Message);
}
示例6: Cannot_remove_property_when_used_by_primary_key
public void Cannot_remove_property_when_used_by_primary_key()
{
var entityType = new EntityType(typeof(Customer), new Model());
var property = entityType.GetOrAddProperty(Customer.IdProperty);
entityType.GetOrSetPrimaryKey(property);
Assert.Equal(
Strings.PropertyInUse("Id", typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(() => entityType.RemoveProperty(property)).Message);
}