You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
List<Guid>productCodes=GetProductCodes();varproducts=await_context.Products.Where(x =>productCodes.Contains(x.ProductCode)).GroupBy(x =>x.ProductCode).Select(x =>x.First())// workaround for `DistinctBy`.Select(x =>new{SupplierId=x.Supplier.Id,WarehouseId=x.Warehouse.Id,x.ProductCode,x.Price, ...}).ToListAsync();
Result:
InvalidOperationException: The LINQ expression 'ProjectionBindingExpression: 0' could not
be translated. Either rewrite the query in a form that can be translated, or switch to
client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable',
'ToList', or 'ToListAsync'.
I use the GroupBy/Select-First workaround instead of DistinctBy which is currently unsupported.
I assume from the error message that the projection in .Select() is the problem; when I remove that the query works. I could perform the projection afterwards, but then I'd be fetching large quantities of data for nothing.
Is there a way to workaround this issue until there is DistinctBy support?
EF Core version: 7.0.16
Database provider: Npsql
Target framework: 7.0
Operating system: linux
IDE: vscode 1.90.2
The text was updated successfully, but these errors were encountered:
Originally asked on SO without resolution.
A query:
Result:
I use the
GroupBy/Select-First
workaround instead ofDistinctBy
which is currently unsupported.I assume from the error message that the projection in
.Select()
is the problem; when I remove that the query works. I could perform the projection afterwards, but then I'd be fetching large quantities of data for nothing.Is there a way to workaround this issue until there is DistinctBy support?
EF Core version: 7.0.16
Database provider: Npsql
Target framework: 7.0
Operating system: linux
IDE: vscode 1.90.2
The text was updated successfully, but these errors were encountered: