【问题标题】:Linq query for unique i'd collection based on one another column value基于另一个列值的唯一 id 集合的 Linq 查询
【发布时间】:2018-06-04 20:38:16
【问题描述】:

我有一个集合(数据表包含三列 A、B 和 C,其中有不同的值)。我需要一个基于不同列“A”和“C”列作为优先级的唯一集合

1st priority -  completed
2nd priority - business 
3rd priority - System

如果找到一个优先级需要忽略其余两个

Input Collection

Required Collection

【问题讨论】:

    标签: c# linq linq-to-sql linq-to-xml


    【解决方案1】:
    List<String> orderBy = new List<String> { "Completed", "Business", "System" };
    
    dt = dt.AsEnumerable()
           .GroupBy(r => new {A = r["A"], C = r["C"]})
           .Select(g => g.OrderBy(r => orderBy.indexOf(r["C"]).First()))
           .CopyToDataTable();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多