C
C#2y ago
nlohim

✅ LINQ GroupBy error

I don't understand what am I missing when trying to perform a simple GroupBy?
18 Replies
Amos
Amos2y ago
@talje since this is a database call use await. Using .Where() here also var query = await context.DosimeterAssocation.Where(x=>x.Barcode).ToListAsync();
nlohim
nlohimOP2y ago
@Ayymoss this is GroupBy not Where
Amos
Amos2y ago
Certain database provides will be able to translate that GroupBy LINQ method. The one you're using may not work.
nlohim
nlohimOP2y ago
I'm using MSSQL
Amos
Amos2y ago
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
Amos
Amos2y ago
@talje
nlohim
nlohimOP2y ago
I tried awaiting, didn't work
Amos
Amos2y ago
Is your method async?
nlohim
nlohimOP2y ago
Yeah ofc, it wouldn't compile otherwise
Amos
Amos2y ago
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
nlohim
nlohimOP2y ago
I have tried that by calling ToList() before GroupBy(), the result is the same error
Amos
Amos2y ago
Try following what I did using await and async methods You don't really want to mix them since .ToList is not asynchronous
Angius
Angius2y ago
test is no longer in the database tho, it's just a regular list Nothing async to be done there
Amos
Amos2y ago
Ya - the EFCore query is async though, second is in memory grouping
Angius
Angius2y ago
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 such
Amos
Amos2y ago
I have tried that by calling ToList() before GroupBy(), the result is the same error
I think they're talking about doing .ToList() on the DbSet then .GroupBy() TIL
Accord
Accord2y ago
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.
nlohim
nlohimOP2y ago
/close
Want results from more Discord servers?
Add your server