EF Core: Must be reducible node

.net-core entity-framework entity-framework-core

Question

I am not sure why I am getting the error: "Must be reducible node"

This is my query. I am running Core 2 with EF Core 2.2 (So I should have the fixes that occurred in previous versions)

    IQueryable<Gizmo> gizmos = _context.Gizmo;


    IQueryable<GizmoViewModel> dataReferences = (
        gizmos.SelectMany(j => j.DataReferences.Select(r =>
            new GizmoViewModel()
            {
                GizmoId = j.Id,
                DataId = r.DataId
            }
        ))
    );
1
2
12/19/2018 4:55:14 PM

Accepted Answer

Simply (and sadly) you are hitting one of the current EF Core query translation bugs.

Looks like it's caused by the accessing the outer SelectMany lambda parameter inside the inner Select expression.

The workaround is to use another SelectMany overload having a second lambda with both outer and inner parameters (which I guess is used by C# compiler when converting LINQ query syntax):

IQueryable<GizmoViewModel> dataReferences = (
    gizmos.SelectMany(j => j.DataReferences, (j, r) =>
        new GizmoViewModel()
        {
            GizmoId = j.Id,
            DataId = r.DataId
        }
    )
);
5
12/19/2018 5:01:22 PM

Popular Answer

Try to include DataReferences maybe?

Your code revised:

IQueryable<GizmoViewModel> dataReferences = (
        gizmos.SelectMany(j => j.DataReferences.Select(r =>
            new GizmoViewModel()
            {
                GizmoId = j.Id,
                DataId = r.DataId
            }
        ))
.Include(m => m.DataReferences)


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