我的 SQL 查询按预期工作:
SELECT SUM(outcome), toaddress
FROM lot l
JOIN incomingpayment ip
ON l.incomingpayment_id = ip.id
WHERE outcome > 0
GROUP BY ip.toaddress
ORDER BY SUM(outcome) DESC
我试图把它变成一个 LINQ 语句,但无论如何都没有取得很大的成功:
var result =
from l in session.Query<Lot>().ToList()
join ip in session.Query<IncomingPayment>().ToList()
on l.IncomingPayment equals ip
where l.Outcome > 0
group ip by new {ip.ToAddress}
into g
select new
{
Address = g.Key,
SumAmount = g.Sum(x => x.Outcome)
};
Outcome
最后一行是 aLot
的字段,由于我正在分组IncomingPayment
( ),因此在通话中group ip...
不可用。g.Sum()
我在这里想念什么?