相关疑难解决方法(0)

如何将行号投射到Linq查询结果中

如何将行号投影到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>();
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,"Rank = i ++"行引发了以下编译时异常:

"表达式树可能不包含赋值运算符"

linq row-number

34
推荐指数
1
解决办法
4万
查看次数

在LINQ Select期间访问递增的整数

Dim project = new Project(1)
Dim tasks = Task.GetTasks()
Return <?xml version="1.0" encoding="UTF-8"?>
               <Project xmlns="http://schemas.microsoft.com/project">
                   <Name><%= project.name %></Name>
                   <Tasks>
                       <%= tasks.Select(Function(t) _
                           <Task>
                               <ID><%= tasks.IndexOf(t) + 1 %></ID>                               
                           </Task> _
                           ) %>
                   </Tasks>
               </Project>
Run Code Online (Sandbox Code Playgroud)

我试图tasks.IndexOf(t) + 1用一些更简单的东西来取代.这有什么内置功能吗?

Hrmm xml文字在这里似乎没有很好的翻译....

c# vb.net

2
推荐指数
1
解决办法
598
查看次数

标签 统计

c# ×1

linq ×1

row-number ×1

vb.net ×1