日期:2014-05-20  浏览次数:20736 次

下列查询如何转换成LINQ,谢谢
SELECT BH,GroupID , COUNT(*) AS Expr1 
FROM CataLogDetail 
where ((GroupID = 1) AND (Company =66)) 
AND ((LB = '身份') AND (LM IN ('合同工')) 
OR (LB = '学历') AND (LM IN ('本科')) )
group by bh ,GroupID
having (count(*)=2)

------解决方案--------------------
C# code

var query=from c in db.CataLogDetail
          where (c.GroupID==1 && c.Comany==66)
          &&(c.LB=="身份" && new string[]{"合同工"}.Contains(c.LM))
          || (c.LB=="学历" && new string[]{"本科"}.Contains(c.LM))
          group c by new {c.bh,c.GroupID} into g
          where  g.Count()==2
          select new 
          {  
              g.Key.bh,
              g.Key.GroupID,
              Expr1=g.Count()
          };
          //代码手打,提供思路参考