常用linq

1.返回列表

var q = (from m in infoList select m.Id).ToList();

var q = (from m in infoList select m.Id).Distinct().ToList();    取出重复的

2.返回字典

var q = (from m in infoList select m).ToDictionary(p => p.Id);

3.group by

var q =  (from p in db.Products group p by p.CategoryID into g select g); 

var q =  (from p in db.Products group p by p.CategoryID into g select new { g.Key, MaxPrice = g.Max(p => p.UnitPrice) }); 

var q =  (from p in db.Products group p by new { X = p.UnitPrice >10 } into g select g);     //分为单价大于10和小于等于10的两组

原文地址:https://www.cnblogs.com/gameshan/p/5028985.html