我想取的有儿孙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。 –