❔ EF Core DistinctBy alternative
Hey guys, is there like no way to use a DistinctBy alternative with EF Core? I tried this:
But this throws an error:
19 Replies
What error?
the one from below
Ah, whoops, missed it somehow
no worries 😄
I extracted the GroupBy().Select(x => x.First()) to my actual code for testing - obviously same issue
could it be something to do with the object/property itself?
Unless that
Name
is a navigation property or some complex object, unlikely
No idea, .GroupBy(...).Select(x => x.First())
is the way to do it
What db are you using?MySQL (pomelo)
Lemme try if it works with Pg
but it's like an older version, 5.6.42
Maybe it's MySQL issue
ah
Makes me suspicious that might be it
ah welp
sadly the hosting I'm using doesn't wanna upgrade the version
oh welp, guess I just gotta stick with client-side eval
Or change hosting ¯\_(ツ)_/¯
Or use a cloud database, Supabase offers Postgres hosting with a free tier, for example
for most apps I'm using something different, I'm only using this one because of the cheap price coupled with .NET hosting, domain, e-mails and unlimited DBs
I'll check supabase out
welp, don't know whether 500 MB is enough
but yeah, that's outside this question, so thanks for the help anyway
Well, someone already raised the issue on the EF Core repo: https://github.com/dotnet/efcore/issues/27470
A year ago
So give it a year or two more and it might work
yeah in my search for an alternative to that I did come across that issue as well 😄
but alas
And it seems it doesn't work with Postgres either
It seems to me the query works, it just needs to get evaluated by the client from what I understand. Try to add an execution method in the end such as AsEnumerable()
well that's exactly what I'm trying to avoid here
Okay but it seems EF can’t translate this properly for your db provider so I don’t think that’s it’s possible to avoid. You could ofc use a different db but @ZZZZZZZZZZZZZZZZZZZZZZZZZ said it doesn’t work for his Postgress DB either
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.