本文整理汇总了C#中EntityType.GetOrAddIndex方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetOrAddIndex方法的具体用法?C# EntityType.GetOrAddIndex怎么用?C# EntityType.GetOrAddIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.GetOrAddIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cannot_remove_property_when_used_by_an_index
public void Cannot_remove_property_when_used_by_an_index()
{
var entityType = new EntityType(typeof(Customer), new Model());
var property = entityType.GetOrAddProperty(Customer.IdProperty);
entityType.GetOrAddIndex(property);
Assert.Equal(
Strings.PropertyInUse("Id", typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(() => entityType.RemoveProperty(property)).Message);
}
示例2: Can_add_retrieve_and_remove_indexes
public void Can_add_retrieve_and_remove_indexes()
{
var entityType = new EntityType(typeof(Order), new Model());
var property1 = entityType.GetOrAddProperty(Order.IdProperty);
var property2 = entityType.GetOrAddProperty(Order.CustomerIdProperty);
Assert.Equal(0, entityType.Indexes.Count);
Assert.Null(entityType.RemoveIndex(new Index(new[] { property1 })));
var index1 = entityType.GetOrAddIndex(property1);
Assert.Equal(1, index1.Properties.Count);
Assert.Same(index1, entityType.GetIndex(property1));
Assert.Same(index1, entityType.FindIndex(property1));
Assert.Same(property1, index1.Properties[0]);
var index2 = entityType.AddIndex(new[] { property1, property2 });
Assert.Equal(2, index2.Properties.Count);
Assert.Same(index2, entityType.GetOrAddIndex(new[] { property1, property2 }));
Assert.Same(index2, entityType.FindIndex(new[] { property1, property2 }));
Assert.Same(property1, index2.Properties[0]);
Assert.Same(property2, index2.Properties[1]);
Assert.Equal(2, entityType.Indexes.Count);
Assert.Same(index1, entityType.Indexes[0]);
Assert.Same(index2, entityType.Indexes[1]);
Assert.Same(index1, entityType.RemoveIndex(index1));
Assert.Null(entityType.RemoveIndex(index1));
Assert.Equal(1, entityType.Indexes.Count);
Assert.Same(index2, entityType.Indexes[0]);
Assert.Same(index2, entityType.RemoveIndex(new Index(new[] { property1, property2 })));
Assert.Equal(0, entityType.Indexes.Count);
}