【问题标题】:Distinct on with entity framework core与实体框架核心不同
【发布时间】:2020-01-26 09:28:05
【问题描述】:

您好,我想知道是否有办法在 ef 核心上使用 disinct?我浏览了 npgsql 文档,找不到任何对我有帮助的东西。那我倒霉了吗?或者有什么解决办法?

【问题讨论】:

标签: sql postgresql entity-framework entity-framework-core


【解决方案1】:

看来我们现在只能用FromSql来做,这是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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 2020-05-16
    • 1970-01-01
    相关资源
    最近更新 更多