✅ LINQ GroupBy error
I don't understand what am I missing when trying to perform a simple GroupBy?
18 Replies
@talje since this is a database call use await.
Using
.Where()
here also
var query = await context.DosimeterAssocation.Where(x=>x.Barcode).ToListAsync();
@Ayymoss this is GroupBy not Where
Certain database provides will be able to translate that GroupBy LINQ method. The one you're using may not work.
I'm using MSSQL
I'll check mine and see if that LINQ works with PostgreSQL
GroupBy didn't work for me either
You could get the data you need then do it in memory
@talje
I tried awaiting, didn't work
Is your method async?
Yeah ofc, it wouldn't compile otherwise
I ask cuz "didn't work" isn't very helpful 😄
But yeah. I'd suggest doing filtering in database query then groupby in memory
if you need everything, then in my screenshot that shows that
I have tried that by calling ToList() before GroupBy(), the result is the same error
Try following what I did using await and async methods
You don't really want to mix them since .ToList is not asynchronous
test
is no longer in the database tho, it's just a regular list
Nothing async to be done thereYa - the EFCore query is async though, second is in memory grouping
On the topic, though:
.GroupBy()
can't really be translated to LINQ on its own. You'd need to pair it with .Select()
and grab just the keys or some of the properties of those keys or some suchI have tried that by calling ToList() before GroupBy(), the result is the same errorI think they're talking about doing .ToList() on the DbSet then .GroupBy() TIL
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity./close