Comment puis-je projeter le numéro de ligne sur le jeu de résultats de la requête linq.
Au lieu de dire:
champ1, champ2, champ3
champ1, champ2, champ3
J'aimerais:
1, champ1, champ2, champ3
2, champ1, champ2, champ3
Voici ma tentative:
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>();
}
}
Malheureusement, la ligne "Rank = i ++" lève l'exception de compilation suivante:
"Une arborescence d'expression ne peut pas contenir d'opérateur d'affectation"