我有一个如下列表
Name Score Date
S1 2 15/02/2013
S1 4 15/02/2013
S2 0 15/02/2013
My desired out should be
S1 6 15/02/2013
为此,我将 LINQ 代码编写为
(from _data in _rawData
group _data by new { _data.Date, _data.Name } into gp orderby gp.Key.Date
select new
{
score = gp.Sum(_score => _score.Score),
store = gp.Max(_store => _store.Name),
Date = gp.Max(_Date => _Date.Date)
}).OrderByDescending(_score => _score.score)
.ToList().
ForEach(item => _timeLiner.Add(new TimeLiner()
{
id = _id++.ToString(),
start = item.auditDate.ToString(),
title = "TopStore: " + item.store
}
我尝试使用.Take(1).ToList()
, Single()
, SingleOrDefault()
,First()
但未能获得所需的输出。相反,我得到了
S1 6 15/02/2013
S2 0 15/02/2013