This should be really simple. I want a Dictionary with a list of records from a Customers table with that property/field value (RegionCode).
I thought this would work (works fine in LinqPad):
await db.Customers
.GroupBy(o => o.RegionCode)
.Select(o => new { o.Key, Customers = o.ToList() })
.ToDictionaryAsync(o => o.Key, o => o.Customers)
But I get:
System.InvalidOperationException: The LINQ expression 'ToList<Customer>(GroupByShaperExpression:
KeySelector: c.RegionCode,
ElementSelector:EntityShaperExpression:
EntityType: Customer
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
)' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Basically, similar to this question but in Linq-to-SQL.
Any ideas?