如何將行號投影到linq查詢結果集上。如何將行號投影到Linq查詢結果
你可以這樣說的:
字段1,字段2,字段3
字段1,字段2,字段3
我想:
1,字段1,字段2,字段3
2 ,field1,field2,field3
這是我的嘗試在此:
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>();
}
}
不幸的是,「等級= I ++」線引發以下的編譯時例外:
「表達式樹可以不包含一個賦值操作符」
[你如何索引字段添加到LINQ結果的可能的複製(http://stackoverflow.com/questions/269058/how-do-you-add-an-index-field- to-linq-results) – 2016-07-13 03:28:25