-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Milestone
Description
From o In db.Orders
Group By o.CustomerID Into g = Group
Select g.Count()InvalidOperationException : The LINQ expression '$VB$ItAnonymous' 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'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Expression:
DbSet<Order>()
.GroupBy(
keySelector: o => o.CustomerID,
resultSelector: (CustomerID, $VB$ItAnonymous) => new VB$AnonymousType_0<string, IEnumerable<Order>>(
CustomerID = CustomerID,
g = $VB$ItAnonymous
))
.Select($VB$It => $VB$It.g
.Count())
🩹 Workaround
Rewriting it using method calls to avoid the problematic part of the expression tree works.
dbContext.Orders _
.GroupBy(Function(o) o.CustomerID) _
.Select(Function(g) g.Count())SELECT COUNT(*)
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]Reactions are currently unavailable