I have a function like this
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();
}
Where a Score
is defined by
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; }
}
Here, what I really want is a List<ViewScore>
where ViewScore
is defined by
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()
}
Is this possible to do all in the LINQ query or do I need to create helper methods?
At the very least, how do I select only the columns s.score1
, s.name
and s.playdate
instead of all of them (via select
) ?