复杂查询
Mego 还支持一些更高级的LLINQ查询写法,本文只列出一部分。
分组汇总查询
using (var db = new OrderManageEntities())
{
var query = from a in db.Products
group a by a.Category into g
select new
{
g.Key,
Count = g.Count(),
Max = g.Max(a => a.Id)
};
var data = query.ToArray();
}
分组查询及分页
using (var db = new OrderManageEntities())
{
var query = (from a in db.Products
group a by a.Category into g
select new
{
g.Key,
List = g
})
.Skip(2).Take(2);
var data = query.ToArray();
}
连接分组查询
using (var db = new OrderManageEntities())
{
var query = from a in db.Orders
join b in db.OrderDetails on a.Id equals b.OrderId into g
select new
{
Order = a,
MaxId = g.Max(m => m.Id)
};
var data = query.ToArray();
}
连接分组查询及分页
using (var db = new OrderManageEntities())
{
var query = (from a in db.Orders
join b in db.OrderDetails on a.Id equals b.OrderId into g
select new
{
Order = a,
List = g
})
.Skip(5).Take(5);
var data = query.ToArray();
}
原文地址:https://www.cnblogs.com/CarefreeXT/p/8747750.html
时间: 2024-10-19 14:17:24