【发布时间】:2016-01-31 15:02:28
【问题描述】:
我有这样的功能
private List<Score> getPageNRows ( int N )
{
// Returns object corresponding to the rows of the table
// on "page" N of the scores page
return (from s in this._SD.Scores
orderby s.score1 descending
select s)
.Skip(ScoresController._scoresPerPage * (N - 1))
.Take(ScoresController._scoresPerPage * N)
.ToList();
}
Score 的定义是
public partial class Score
{
public Score()
{
GameLogs = new HashSet<GameLog>();
}
public int id { get; set; }
[Column("score")]
public int score1 { get; set; }
[StringLength(50)]
public string name { get; set; }
public DateTime playdate { get; set; }
public virtual ICollection<GameLog> GameLogs { get; set; }
}
在这里,我真正想要的是 List<ViewScore>,其中 ViewScore 由
public class ViewScore
{
public int score { get; set; } // corresponds directly to score1 in Score class
public string name { get; set; } // corresponds directly to name in Score
public string datestr { get; set; } // corresponds to playdate.ToString()
}
这是否可以在 LINQ 查询中完成,还是我需要创建辅助方法?
至少,我如何只选择列s.score1、s.name 和s.playdate 而不是全部(通过select)?
【问题讨论】:
-
@DavidBetz 你这是什么意思?
-
没关系,其他人(例如 Arghya C)和我说的一样,但作为一个可靠的答案。 :)
标签: c# asp.net asp.net-mvc algorithm linq