1
這裏是我的數據模型的樣本:使用在實體框架的ICollection的一個包含
class Invoice
{
public ICollection<LineItem> LineItems { get; set; }
}
class LineItem
{
public string Text { get; set; }
public Invoice Invoice { get; set; }
public Category Category { get; set; }
}
class Category
{
public string Name { get; set; }
}
我不能急於負荷的LineItem像這樣:
return DataContext.Invoices.First().Include("LineItems.Category");
怎麼可以這樣使用Lambda我做?
return DataContext.Invoices.First().Include(li => li.LineItems); //I can't chain any more includes since LineItems is an ICollection
編輯: 我試圖
return DataContext.Invoices.Include(i => i.LineItems.First().Category).Single();
和它導致了ArgumentException
使用以下信息:
包含路徑表達式必須是指所定義的導航屬性 在類型上。使用虛線路徑作爲參考導航 屬性和Select運算符用於收集導航 屬性。參數名:路徑
這句法並沒有爲我工作,檢查更新OP。 –
對不起,我偶然編輯了你的文章,然後我將其回滾。 –
請解釋爲什麼這會起作用,而OP所嘗試的卻沒有。 – ArtB