如何在Entity Framework Core 2.0.1查询中包含内部列表(位于另一个列表中)?
这是我尝试过的但没有成功:
clase = repClase.ListQueryable(
//Specification
new ApplicationCore.Specifications.ClaseFilterByIdAndIdArticuloWithIncludesSpecification(idClase, idArticuloParam)
)
.Include(c => c.ReferenciasConstructor)
.ThenInclude(rc => rc.Select(rc1 => rc1.ReferenciaFabricanteTieneReferenciaConstructor))
.FirstOrDefault();
它抛出的错误: “属性表达式'rc => {来自rc select [rc1] .ReferenciaFabricanteTieneReferenciaConstructor}中的ReferenciaConstructor rc1'无效。表达式应代表属性访问:'t => t.MyProperty'。”。
类:
[Table("Clases", Schema = "public")]
public class Clase
{
...
[InverseProperty("Clase")]
public IList<ReferenciaConstructor> ReferenciasConstructor { get; set; }
}
[Table("ReferenciasConstructor", Schema = "public")]
public class ReferenciaConstructor
{
[Key]
public int Id { get; set; }
...
//JOIN TABLE
[InverseProperty("ReferenciaConstructor")]
public IList<ReferenciaFabricanteTieneReferenciaConstructor> ReferenciaFabricanteTieneReferenciaConstructor { get; set; }
}
//JOIN TABLE
[Table("ReferenciaFabricanteTieneReferenciaConstructor", Schema = "public")]
public class ReferenciaFabricanteTieneReferenciaConstructor {
[Key]
public int IdReferenciaFabricante { get; set; }
[ForeignKey("IdReferenciaFabricante")]
public ReferenciaFabricante ReferenciaFabricante { get; set; }
[Key]
public int IdReferenciaConstructor { get; set; }
[ForeignKey("IdReferenciaConstructor")]
public ReferenciaConstructor ReferenciaConstructor { get; set; }
}
答案 0 :(得分:0)
您无法使用Include
来选择目的。只需select
所需的属性。
clase = repClase.ListQueryable(
//Specification
new ApplicationCore.Specifications.ClaseFilterByIdAndIdArticuloWithIncludesSpecification(idClase, idArticuloParam)
)
.Include(c => c.ReferenciasConstructor)
.SelectMany(rc => rc.ReferenciasConstructor.Select(rc1 => rc1.ReferenciaFabricanteTieneReferenciaConstructor))
.FirstOrDefault();