2013-07-08 73 views
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() 
     orderby ... 
     select new { A = detail, B = (h==null? 0: h.Field<int>("num")) }; 

对于上面的查询,我该如何命令B? 谢谢linq left join datatable and oder by the null value

回答

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) } 
+0

工作,谢谢! – shuan