常用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的两组

posted on 2015-12-08 14:20  gameshan  阅读(150)  评论(0编辑  收藏  举报

导航