LinQ Group By


  • 普通
var list = from s in db.mm_ShopMas
                       where s.IsStop == false
                       group s by s.SpaceId;

   Sql执行时会取全部数据。

 

  • into
var list = from s in db.mm_ShopMas
                       where s.IsStop == false
                       group s by s.SpaceId into g
                       select g;

  Sql执行时会取全部数据。

  Select
  

var list = from s in db.mm_ShopMas
                       where s.IsStop == false
                       group s by s.SpaceId into g
                       select new { g.Key,Total = g.Count()};

 

  Sql执行的结果为汇总数据。

  • 多列Group
var list = from s in db.mm_ShopMas
                       where s.IsStop == false
                       group s by new { s.SpaceId ,s.TradeId} into g
                       select new { g.Key, Total = g.Count() };

  Sql执行结果为汇总数据。

 select new {g.Key.TradeId,g.Key.SpaceId,Tocal=g.Count()}

 

select new {g.Key,Tocal=g.Count()}

  • 表达式

 

var list = from s in db.mm_ShopMas
                       where s.IsStop == false
                       group s by new { IdFirst = s.ShopId / 1000 } into g
                       select new { g.Key, Total = g.Count() };

Sql执行结果为汇总数据:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM