Это должно быть действительно просто. Мне нужен словарь со списком записей из таблицы «Клиенты» с этим значением свойства / поля (RegionCode).
Я думал, что это будет работать (отлично работает в LinqPad):
await db.Customers
.GroupBy(o => o.RegionCode)
.Select(o => new { o.Key, Customers = o.ToList() })
.ToDictionaryAsync(o => o.Key, o => o.Customers)
Но я получаю:
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.
По сути, похоже на этот вопрос , но в Linq-to- SQL.
Есть идеи?