我有以下查詢:實體框架,MVC 3,排序依據在LINQ到實體
model.Page = db.Pages
.Where(p => p.PageId == Id)
.Include(p => p.Series
.Select(c => c.Comics
.Select(col => col.Collection)))
.SingleOrDefault();
這個偉大的工程,但我現在需要一個被稱爲「ReadingOrder」屬性訂購漫畫。
我已經試過:
model.Page = db.Pages
.Where(p => p.PageId == Id)
.Include(p => p.Series.Select(c => c.Comics.OrderBy(o => o.ReadingOrder)
.Select(col => col.Collection)))
.SingleOrDefault();
但是這會導致以下錯誤:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path
任何想法,這個錯誤是什麼意思?
在此先感謝
編輯:
我的模型:
public class Page
{
public int PageId { get; set; }
public string Title { get; set; }
public ICollection<Series> Series { get; set; }
}
public class Series
{
public int SeriesId { get; set; }
public int PageId { get; set; }
public string Title { get; set; }
public Page Page { get; set; }
public ICollection<Comic> Comics { get; set; }
}
public class Comic
{
public int ComicId { get; set; }
public string Title { get; set; }
public int ReadingOrder { get; set; }
public string Subtitle { get; set; }
public int CollectionId { get; set; }
public Collection Collection { get; set; }
}
public class Collection
{
public int CollectionId { get; set; }
public string Title { get; set; }
public ICollection<Comic> Comics { get; set; }
}
Slauma - 你是否僱用?!!再次,非常感謝您花時間研究這一點。我現在選擇了選項1,只是爲了提高速度,但是在某些時候會考慮其他兩個選項。再次感謝! – Sniffer
@Sniffer:我不會推薦你聘請你寫作的人作爲選項3帶有問號的單個單詞:)其實我不確定投影是否與這些多重嵌套集合有關。 – Slauma