Entity Framework Core - Include nested list inside list

c# entity-framework-core

Question

How can I include an inner list, which is inside another list, in a Entity Framework Core 2.0.1 query?

This is what I tried without success:

clase = repClase.ListQueryable(
    //Specification
    new ApplicationCore.Specifications.ClaseFilterByIdAndIdArticuloWithIncludesSpecification(idClase, idArticuloParam)
)
.Include(c => c.ReferenciasConstructor)
.ThenInclude(rc => rc.Select(rc1 => rc1.ReferenciaFabricanteTieneReferenciaConstructor))
.FirstOrDefault();

And the error it throws: "The property expression 'rc => {from ReferenciaConstructor rc1 in rc select [rc1].ReferenciaFabricanteTieneReferenciaConstructor}' is not valid. The expression should represent a property access: 't => t.MyProperty'.".

Classes:

[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; }
}
1
0
1/16/2018 8:39:55 AM

Accepted Answer

This is a known Intellisense issue with the ThenInclude overload for collection type navigation properties, tracked by the Completion missing members of lambda parameter in fault tolerance case #8237 Roslyn GitHub issue.

Until it gets fixed, simply type the name of the property and it will compile successfully and work as expected.

.ThenInclude(mu => mu.ParseSubTrees) 

Update: Now it's even specifically mentioned in the Including multiple levels section of the EF Core documentation:

Note

Current versions of Visual Studio offer incorrect code completion options and can cause correct expressions to be flagged with syntax errors when using the ThenInclude method after a collection navigation property. This is a symptom of an IntelliSense bug tracked at https://github.com/dotnet/roslyn/issues/8237. It is safe to ignore these spurious syntax errors as long as the code is correct and can be compiled successfully.

41
10/10/2018 8:06:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow