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