✅ LINQ GroupBy error

Ttalje1/25/2023
I don't understand what am I missing when trying to perform a simple GroupBy?
Image
AAyymoss1/25/2023
@talje since this is a database call use await.

Using .Where() here also

var query = await context.DosimeterAssocation.Where(x=>x.Barcode).ToListAsync();
Ttalje1/25/2023
@Ayymoss this is GroupBy not Where
AAyymoss1/25/2023
Certain database provides will be able to translate that GroupBy LINQ method. The one you're using may not work.
Ttalje1/25/2023
I'm using MSSQL
AAyymoss1/25/2023
I'll check mine and see if that LINQ works with PostgreSQL
AAyymoss1/25/2023
GroupBy didn't work for me either
AAyymoss1/25/2023
You could get the data you need then do it in memory
AAyymoss1/25/2023
@talje
Image
Ttalje1/25/2023
I tried awaiting, didn't work
AAyymoss1/25/2023
Is your method async?
Ttalje1/25/2023
Yeah ofc, it wouldn't compile otherwise
AAyymoss1/25/2023
I ask cuz "didn't work" isn't very helpful 😄
AAyymoss1/25/2023
But yeah. I'd suggest doing filtering in database query then groupby in memory
AAyymoss1/25/2023
if you need everything, then in my screenshot that shows that
Ttalje1/25/2023
I have tried that by calling ToList() before GroupBy(), the result is the same error
AAyymoss1/25/2023
Try following what I did using await and async methods
AAyymoss1/25/2023
You don't really want to mix them since .ToList is not asynchronous
AAngius1/25/2023
test is no longer in the database tho, it's just a regular list
AAngius1/25/2023
Nothing async to be done there
AAyymoss1/25/2023
Ya - the EFCore query is async though, second is in memory grouping
AAngius1/25/2023
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
AAyymoss1/25/2023
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()
AAyymoss1/25/2023
TIL
AAccord1/26/2023
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.
Ttalje1/30/2023
/close