本文整理汇总了C#中EntityType.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetIndex方法的具体用法?C# EntityType.GetIndex怎么用?C# EntityType.GetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.GetIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIndex_throws_if_index_not_found
public void GetIndex_throws_if_index_not_found()
{
var entityType = new EntityType(typeof(Customer), new Model());
var property1 = entityType.GetOrAddProperty(Customer.IdProperty);
var property2 = entityType.GetOrAddProperty(Customer.NameProperty);
Assert.Equal(Strings.IndexNotFound("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<ModelItemNotFoundException>(
() => entityType.GetIndex(new[] { property1, property2 })).Message);
entityType.AddIndex(property1);
Assert.Equal(Strings.IndexNotFound("{'" + Customer.IdProperty.Name + "', '" + Customer.NameProperty.Name + "'}", typeof(Customer).FullName),
Assert.Throws<ModelItemNotFoundException>(
() => entityType.GetIndex(new[] { property1, property2 })).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);
}