【问题标题】:Entity Framework Core take one and skip other duplicate item in a tableEntity Framework Core 取一个并跳过表中的其他重复项
【发布时间】:2018-09-14 04:58:15
【问题描述】:

我有一个包含string 列表的表,并且表中的许多项目具有相同的string 和不同的ID,现在我想从表中取出所有项目但不超过一个具有相同string 的项目。

示例表

id    -   string
------------------
 1   ---   A 
 2   ---   B 
 3   ---   B 
 4   ---   C 
 5   ---   D 
 6   ---   D 
 7   ---   F

查询后的列表应该是这样的

A, B, C, D, F

如何使用 LINQ 做到这一点?

【问题讨论】:

    标签: c# linq entity-framework-core


    【解决方案1】:

    我想你可以这样做:

    var result = Context.yourTable.Select(t => t.fieldName).Distinct();

    因此,基本上,您的查询只会获得“fieldName”的不同值(无论您的情况如何)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 2019-06-13
      • 2018-09-25
      • 1970-01-01
      相关资源
      最近更新 更多