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

sql 2 linq
SQL code

select COUNT(*) as '总数','已占用'=
(select COUNT(distinct(graveno)) from d_necro where d_necro.garea='2001') 
from Graves where FgrId ='2001'


这个用linq咋写

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

var query=from g in db.Graves
          where g.FgrId== 2001
          select new 
          {
            总数=db.Graves.Count(m=>m.FgrId== 2001),
            已占用=db.d_necro.Where(n=>n.garea==2001).Select(n=>n.graveno).Distinct().Count()
          };