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

LINQ中求和和汇总只想做一次怎么实现?.
SQL语句为:select Sum(t.b), Count(t.a) from tbl_customer t

LINQ分开实现:
SumA = (from c in vSession.Linq<Customer>()
  select c.a).Sum();
CountB = (from c in vSession.Linq<Customer>()
  select c.b).Count();

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

//更改成这种形式
 var query = from w in data.News
                        select new
                        {
                            sum=data.News.Sum(m=>m.NewsId),
                            count=data.News.Select(m=>m.NewsState).Count()
                        };