我想取的有兒孫EF核2.0 ThenInclude()導航不可達
實體實體下面的代碼第一公約和如下
//This is the father class
public partial Class Solicitud{
[InverseProperty("Solicitud")]
public virtual ICollection<Operacion> Operaciones { get; set; }
//Other properties
}
//This is the child class
public partial Class Operacion{
[JsonIgnore] //This is so when serializing we don't get a circular reference
[InverseProperty("Operaciones")]
public virtual Solicitud Solicitud { get; set; }
public virtual Practica Practica { get; set; }
//Other Properties
}
//This is the grandchild class
public partial Class Practica
{
String Nombre;
//Other Properties
}
如果我做
context.Solicitudes
.Include(w => w.Operaciones)
.Where(x => x.Profesional == profesional).OrderBy(something);
它的工作原理進行確定,填充「Operaciones」集合,並留下了「實習課」屬性爲空預期。
問題出現時,我試圖讓孫子,通過使用
context.Solicitudes
.Include(w => w.Operaciones)
.ThenInclude(o => o.Practica)
.Where(x => x.Profesional == profesional);
在那裏,它仍然填充Operaciones,但在每個Operacion財產實習課停留空,我得到以下信息
warn: Microsoft.EntityFrameworkCore.Query[100106]
The Include operation for navigation '[w].Operaciones.Practica' is unnecessary and was ignored because the navigation is not reachable in the final query results. See https://go.microsoft.com/fwlink/?linkid=850303 for more information.
這對我來說沒有任何意義,因爲我能很好的做到
String something = solicitud.Operaciones.ElementAt(0).Practica.Nombre;
這是一個錯誤?有什麼辦法可以避免使用嵌套選擇?這些類非常大,因爲它們有很多屬性,並且使用該方法難以保留對域模型的更改。
謝謝。
編輯:編輯標題。
感謝您的迴應! 不幸的是,這是不適合我的情況,因爲Practica是具有參考標準化值的表格,而Operacion使用Practica來說明在某一天進行了哪種類型的外科手術。 我真的很想能夠返回一個Solicitudes列表。 我也沒有詳細說明,因爲「Practicas」是一個參考表,一個Operacion有一個Practica,但一個Practica有很多Operacions。所以 。這裏(p => p.Operacion.Solicitud.Profesional == profesional) 失敗,因爲p.Operacion不是一個對象,而是一個ICollection。 –