如何将行号投影到 linq 查询结果集。
而不是说:
场 1、场 2、场 3
场 1、场 2、场 3
我想:
1、字段1、字段2、字段3
2、字段1、字段2、字段3
这是我的尝试:
public List<ScoreWithRank> GetHighScoresWithRank(string gameId, int count)
{
Guid guid = new Guid(gameId);
using (PPGEntities entities = new PPGEntities())
{
int i = 1;
var query = from s in entities.Scores
where s.Game.Id == guid
orderby s.PlayerScore descending
select new ScoreWithRank()
{
Rank=i++,
PlayerName = s.PlayerName,
PlayerScore = s.PlayerScore
};
return query.ToList<ScoreWithRank>();
}
}
不幸的是,“Rank=i++”行抛出以下编译时异常:
“表达式树可能不包含赋值运算符”