【发布时间】:2015-07-24 17:46:48
【问题描述】:
我在我的第一个 Code First 项目中。我刚刚学会了如何在两列上添加索引。
[Required]
[Index("IX_NameAndCity", 1, IsUnique = false)]
[MaxLength(900)]
public string Name { get; set; }
[Index("IX_NameAndCity", 2, IsUnique = false)]
[MaxLength(900)]
public string City { get; set; }
这看起来对吗? ^^^
在 LINQ 中使用这些索引有什么特别之处还是透明的?我有一半希望在我的 LINQ 中看到“.IX_NameAndCity”的选择。
这是我现在正在做的事情:
var property = _propertyRepository
.GetProperties()
.FirstOrDefault(x => x.Name == name && x.City == city);
应该是这样的:
var property = _propertyRepository
.GetProperties()
.FirstOrDefault(x => x.IX_NameAndCity.name == name && IX_NameAndCity.City == city);
或者它是否自动知道有一个索引? 谢谢大家!
【问题讨论】:
标签: linq indexing ef-code-first