0
嵌套列表的對象我使用實體框架的核心,我有以下結構:不能包括與實體查詢
class Foo
{
public ICollection<Bar> Bars { get; set; }
}
class Bar
{
public XPTO Xpto { get; set; }
}
class XPTO
{
public string Message { get; set; }
}
我怎樣可以加入我的LINQ查詢的XPTO對象?
我曾嘗試:
context.Foo.Include(o => o.Bars).ToList(); // This gets me the Bars but the XPTO's of them are null
context.Foo.Include(o => o.Bars).ThenInclude(o => o.Select(x => x.Xpto)).ToList(); This throws an error:
System.ArgumentException:屬性表達 'O => {從酒吧在鄰 選擇[x] .Xpto}' 是無效的。該表達式應代表 屬性訪問:'t => t.MyProperty'。
我在這裏錯過了什麼?
https://stackoverflow.com/a/36601380/5621827這可能有幫助 – jitender
它does not。在我的'ThenInclude'中,我只能訪問'Collection'屬性。我嘗試使用'Select'來獲得我想要的字段,但它引發錯誤 –
當您編寫ThenInclude(o => o.Xpto)時收到的錯誤是什麼?因爲如果您看到上述文章的評論,您將無法獲得任何Intellisense的幫助,但它仍然有效 – jitender