按转换分组

时间:2015-04-11 14:30:54

标签: c# sql linq

如何将以下SQL查询转换为lambda表达式?

select MAX(ID),ProcessInstanceID from tblKGWorks 
where FormID = 2598 and FormTypeID =2306
group by ProcessInstanceID

1 个答案:

答案 0 :(得分:0)

试一试:

var qry = tblKGWorks
          .Where(gk=>gk.FormID == 2598 && gk.FormTypeID == 2306)
          .GroupBy(x=>x.ProcessInstanceID)
          .Select(grp=>new{ID = grp.Max(a=>a.ID), ProcessInstanceID = grp.Key});

更多信息:101 Linq Samples