Как я могу спроектировать номер строки в наборе результатов запроса linq.
Вместо того, чтобы сказать:
field1, field2, field3
field1, field2, field3
Я бы хотел:
1, field1, field2, field3
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>();
}
}
К сожалению, строка "Rank = я ++" генерирует следующее исключение для компиляции:
"Дерево выражений может не содержать оператор присваивания"