本文整理汇总了C#中EntityType.AddKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.AddKey方法的具体用法?C# EntityType.AddKey怎么用?C# EntityType.AddKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.AddKey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get_generation_property_returns_generation_property_from_foreign_key_tree
public void Get_generation_property_returns_generation_property_from_foreign_key_tree()
{
var model = new Model();
var leftType = new EntityType("Left", model);
var leftId = leftType.AddProperty("Id", typeof(int), true);
var leftKey = leftType.AddKey(leftId);
var rightType = new EntityType("Right", model);
var rightId1 = rightType.AddProperty("Id1", typeof(int), true);
var rightId2 = rightType.AddProperty("Id2", typeof(int), true);
var rightKey = rightType.AddKey(new[] { rightId1, rightId2 });
var middleType = new EntityType("Middle", model);
var middleProperty1 = middleType.AddProperty("FK1", typeof(int), true);
var middleProperty2 = middleType.AddProperty("FK2", typeof(int), true);
var middleKey1 = middleType.AddKey(middleProperty1);
var middleFK1 = middleType.AddForeignKey(middleProperty1, leftKey, leftType);
var middleFK2 = middleType.AddForeignKey(new[] { middleProperty2, middleProperty1 }, rightKey, rightType);
var endType = new EntityType("End", model);
var endProperty = endType.AddProperty("FK", typeof(int), true);
var endFK = endType.AddForeignKey(endProperty, middleKey1, middleType);
rightId2.RequiresValueGenerator = true;
Assert.Equal(rightId2, endProperty.GetGenerationProperty());
}
示例2: Get_generation_property_returns_generation_property_from_foreign_key_chain
public void Get_generation_property_returns_generation_property_from_foreign_key_chain()
{
var model = new Model();
var firstType = new EntityType("First", model);
var firstProperty = firstType.AddProperty("ID", typeof(int), true);
var firstKey = firstType.AddKey(firstProperty);
var secondType = new EntityType("Second", model);
var secondProperty = secondType.AddProperty("ID", typeof(int), true);
var secondKey = secondType.AddKey(secondProperty);
var secondForeignKey = secondType.AddForeignKey(secondProperty, firstKey, firstType);
var thirdType = new EntityType("Third", model);
var thirdProperty = thirdType.AddProperty("ID", typeof(int), true);
var thirdForeignKey = thirdType.AddForeignKey(thirdProperty, secondKey, secondType);
firstProperty.RequiresValueGenerator = true;
Assert.Equal(firstProperty, thirdProperty.GetGenerationProperty());
}
示例3: CreateKey
private Key CreateKey(EntityType entityType, int startingPropertyIndex = -1, int propertyCount = 1)
{
if (startingPropertyIndex == -1)
{
startingPropertyIndex = entityType.PropertyCount - 1;
}
var keyProperties = new Property[propertyCount];
for (var i = 0; i < propertyCount; i++)
{
var property = entityType.GetOrAddProperty("P" + (startingPropertyIndex + i));
property.ClrType = typeof(int?);
property.IsShadowProperty = false;
keyProperties[i] = property;
keyProperties[i].RequiresValueGenerator = true;
}
return entityType.AddKey(keyProperties);
}
示例4: CreateKey
private Key CreateKey(EntityType entityType, int startingPropertyIndex = -1, int propertyCount = 1)
{
if (startingPropertyIndex == -1)
{
startingPropertyIndex = entityType.PropertyCount;
}
var keyProperties = new Property[propertyCount];
for (int i = 0; i < propertyCount; i++)
{
keyProperties[i] = entityType.GetOrAddProperty("P" + (startingPropertyIndex + i), typeof(int?));
keyProperties[i].GenerateValueOnAdd = true;
}
return entityType.AddKey(keyProperties);
}
示例5: Get_generation_property_returns_generation_property_from_foreign_key_graph_with_cycle
public void Get_generation_property_returns_generation_property_from_foreign_key_graph_with_cycle()
{
var model = new Model();
var leafType = new EntityType("leaf", model);
var leafId1 = leafType.AddProperty("Id1", typeof(int), true);
var leafId2 = leafType.AddProperty("Id2", typeof(int), true);
var leafKey = leafType.AddKey(new[] { leafId1, leafId2 });
var firstType = new EntityType("First", model);
var firstId = firstType.AddProperty("Id", typeof(int), true);
var firstKey = firstType.AddKey(firstId);
var secondType = new EntityType("Second", model);
var secondId1 = secondType.AddProperty("Id1", typeof(int), true);
var secondId2 = secondType.AddProperty("Id2", typeof(int), true);
var secondKey = secondType.AddKey(secondId1);
var firstForeignKey = firstType.AddForeignKey(firstId, secondKey, secondType);
var secondForeignKey1 = secondType.AddForeignKey(secondId1, firstKey, firstType);
var secondForeignKey2 = secondType.AddForeignKey(new[] { secondId1, secondId2 }, leafKey, leafType);
leafId1.RequiresValueGenerator = true;
Assert.Equal(leafId1, secondId1.GetGenerationProperty());
}
示例6: 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);
}
示例7: Adding_a_key_throws_if_properties_from_different_type
public void Adding_a_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.AddKey(idProperty)).Message);
}
示例8: Can_add_and_get_a_key
public void Can_add_and_get_a_key()
{
var entityType = new EntityType(typeof(Customer), new Model());
var idProperty = entityType.GetOrAddProperty(Customer.IdProperty);
var nameProperty = entityType.GetOrAddProperty(Customer.NameProperty);
var key1 = entityType.AddKey(new[] { idProperty, nameProperty });
Assert.NotNull(key1);
Assert.Same(key1, entityType.GetOrAddKey(new[] { idProperty, nameProperty }));
Assert.Same(key1, entityType.Keys.Single());
var key2 = entityType.GetOrAddKey(idProperty);
Assert.NotNull(key2);
Assert.Same(key2, entityType.GetKey(idProperty));
Assert.Equal(2, entityType.Keys.Count());
Assert.Contains(key1, entityType.Keys);
Assert.Contains(key2, entityType.Keys);
}