1.数据筛除重复的(就是剩下的都是不重复的)
list.GroupBy(x => new { x.aid, x.name }).Select(x => x.First());
2.Where条件下查询两个字段
1 var doorBy = door.Where(x => x.f_DoorID == p.f_DoorID).Select(x => new { x.f_DoorNO, x.f_ControllerID });
3.多表联合查询组成一个新结果集
1 var doorBy = (from x in door 2 join y in consumer on p.f_ConsumerID equals y.f_ConsumerID 3 join z in device on p.f_ControllerID equals z.f_ControllerID 4 where x.f_DoorID == p.f_DoorID 5 select new 6 { 7 x.f_ControllerID, 8 x.f_DoorNO, 9 y.f_CardNO, 10 z.F_ControllerSN, 11 }).First();
.First()表示第一条记录。
4.Group By 分组
var PeopleCard = from x in doo group x.Card by new { x.Card, x.SN } into g select g;
5.查询价格在100元以下的前10条记录,并且按价格从低到高显示
1 return View(repository.Books 2 .OrderBy(b=>b.Price) 3 .Where(b=>b.Price<100) 4 .Take(10));