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
}
))
);
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
}
)
);
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)