任何人都可以帮助将以下SQL查询转换为Linq
select
PersonRank,
amount,
(Select sum(p2.Amount) from @PersonRank p2 where p2.PersonRank <= p1.PersonRank)
from @PersonRank P1
order by PersonRank
答案 0 :(得分:1)
试试这个
var result = db.PersonRank(i => new
{
PersonRank = i.PersonRank,
amount = i.amount,
PersonRankSum = (db.PersonRank
.Where(t => t.PersonRank <= i.PersonRank)
.Sum(t => t.Amount)
)
}).OrderBy(i => i.PersonRank);
答案 1 :(得分:0)
var query =
from pr in context.PersonRanks
orderby pr.PersonRank
select new
{
pr.PersonRank,
pr.Amount,
Sum = context.PersonRanks.Where(p => p.PersonRank <= pr.PersonRank).Sum(p => p.Amount)
};