【问题标题】:Entity Framework Core Order By实体框架核心排序依据
【发布时间】:2021-11-17 12:32:34
【问题描述】:

我想从按列排序的特定列中检索数据库中的数据,加上不同的。数据也被明确地提取,但没有排序。我的查询如下所示:

 return context.TableName.OrderBy(l => l.ColumnName).Select(p => p.ColumnName)
            .Distinct().ToList();

【问题讨论】:

    标签: database entity-framework-core blazor


    【解决方案1】:

    Distinct 本身丢弃排序。这是因为实现,它依赖于数据库。所以在Distinct之后订购。

    return context.TableName
       .Select(p => p.ColumnName)
       .Distinct()
       .OrderBy(l => l)
       .ToList();
    

    【讨论】:

    • 但是我必须在选择之前进行排序,否则我无法按表格排序? :)
    • 只有在 Distinct 之后才需要进行 OrderBy。
    猜你喜欢
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2020-05-10
    相关资源
    最近更新 更多