我正在尝试使用EF6进行查询,该查询会急切加载相关对象然后对其进行分组然后计算相关记录的总数并进行分页,但到目前为止我还没有成功。
这是我的尝试,但它只进行连接和分页
_dbcontext.PublicUsers
.Include(x=> x.DocumentIndices)
.OrderBy(x=> x.Lastname)
.ThenBy(x=> x.Firstname)
.Skip((request.PageNumber - 1) * request.PageSize)
.Take(request.PageSize)
.ToList()
.Select(x => new PublicUserList
{
Id = x.Id,
Email = x.Email,
Firstname = x.Firstname,
Lastname = x.Lastname,
Middlename = x.Middlename,
Fullname = x.Fullname,
NoOfResults = x.DocumentIndices.Count()
}).ToList();
有没有办法在EF6的一次访问中进行三次操作(按计数+分页加入+组)?
答案 0 :(得分:0)
除非我误解了这一点,否则我认为这只是删除几行的问题:
_dbcontext.PublicUsers
.OrderBy(x=> x.Lastname)
.ThenBy(x=> x.Firstname)
.Skip((request.PageNumber - 1) * request.PageSize)
.Take(request.PageSize)
.Select(x => new PublicUserList
{
Id = x.Id,
Email = x.Email,
Firstname = x.Firstname,
Lastname = x.Lastname,
Middlename = x.Middlename,
Fullname = x.Fullname,
NoOfResults = x.DocumentIndices.Count()
})
.ToList();