Distinct on with entity framework core

entity-framework entity-framework-core postgresql sql

Question

Hi I was wondering if there was a way to use disinct on with ef core? I have looked through the npgsql documentation and could not find anything which would help me. So am I out of luck? Or is there some workaround?

1
1
9/26/2019 6:52:53 AM

Popular Answer

Seems that we can do it only with FromSql for now, and it's a feature of Postgres:

if (context.Database.IsNpgsql()) // check Postgres provider
{
    var query = context.SomeData.FromSql("select distinct on (id) * from some_data order by id, date desc");
   // actions query.ToListAsync(), query.CountAsync() etc
   // ...
}
else
{
   // Other providers/exception
}
0
10/17/2019 3:42:28 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow