Reputation: 1
I am writing a Linq query that will be applied to an SQL DB. This is the query:
var entitiesGroups = await _context.ProductsDetailsStatisticsView
.GroupBy(p => p.Id, (productDetailsId, info) => new
{
Key = productDetailsId,
Info = info
})
.ToListAsync();
I am getting the following error when this query is evaluated:
Exception: System.InvalidOperationException: variable 'info' of type 'System.Collections.Generic.IEnumerable`1[ProductDetailsStatisticsEntity]' referenced from scope '', but it is not defined
Upvotes: 0
Views: 68
Reputation: 27461
Since you need all records, do grouping on the client side:
var entitiesGroups = (await _context.ProductsDetailsStatisticsView.ToListAsync())
.GroupBy(p => p.Id, (productDetailsId, info) => new
{
Key = productDetailsId,
Info = info
})
.ToList();
Upvotes: 1