这是我的查询分组
var query = (
from fee in _walletRepository.Table
group fee by fee.PartyId into groupResult
select new
{
partyId = groupResult.Select(x => x.PartyId),
Balance = groupResult.Sum(f => f.Receipt > 0 ? f.Receipt : 0) - groupResult.Sum(f => f.Payment > 0 ? f.Payment : 0)
}).OrderByDescending(x => x.Balance);
var tmp = await query.ToPagedListAsync(pageIndex, pageSize);
return new PagedList<OGSWallet>(tmp.Select(x => new OGSWallet
{
PartyId = Convert.ToInt32(x.partyId),
AvailableBalance = x.Balance
}).ToList(), tmp.PageIndex, tmp.PageSize, tmp.TotalCount);
每当我运行查询时,它都会在以下行的查询中抛出错误
var tmp = await query.ToPagedListAsync(pageIndex, pageSize);
?错误:LinqToDB.LinqToDBException:您应该为服务器端 GroupBy() 调用显式指定选定字段,或在 GroupBy() 之前添加 AsEnumerable() 调用以执行客户端分组。
不知道是查询问题还是其他问题?
线路
partyId = groupResult.Select(x => x.PartyId)
有问题。 PartyId
是分组的关键,应从 groupResult.Key
检索
var query = (
from fee in _walletRepository.Table
group fee by fee.PartyId into groupResult
select new
{
partyId = groupResult.Key,
Balance = groupResult.Sum(f => f.Receipt > 0 ? f.Receipt : 0) - groupResult.Sum(f => f.Payment > 0 ? f.Payment : 0)
}).OrderByDescending(x => x.Balance);