linq左边连接数据表并按可空值排序

时间:2013-07-08 05:23:47

标签: linq datatable left-join

var query = from detail in dsApp.AsEnumerable()
        join rate in dsRate.AsEnumerable()
        on detail.Field<string>("ApplicationName") equals
              rate.Field<string>("AppName")
        into g
        from h in g.DefaultIfEmpty()
        orderby  ...
        select new { A = detail, B = (h==null? 0: h.Field<int>("num")) };

对于上述查询,我​​该如何通过B订购? 感谢

1 个答案:

答案 0 :(得分:0)

    var query = from detail in dsApp.AsEnumerable()
    join rate in dsRate.AsEnumerable()
    on detail.Field<string>("ApplicationName") equals
          rate.Field<string>("AppName")
    into g
    from h in g.DefaultIfEmpty()
    select new { A = detail, B = (h==null? 0: h.Field<int>("num")) } into Tmp
    orderby Tmp.num
    select new { A = Tmp.A, B = Tmp.B) }
相关问题