グループ化されたデータを出力してから、再度グループ化しようとしています。
ここにいくつかのサンプルデータがあります(dbから)
私はこれを次のようにグループ化して出力しようとしています:
Best Type Name
- Discipline name
-- Result
-- Result
-- Result
CompetitorBest クラスは次のようになります。
public class CompetitorBest
{
public int ResultId { get; set; }
public string BestTypeName { get; set; }
public int BestTypeOrder { get; set; }
public string DisciplineName { get; set; }
public string ResultValue { get; set; }
public string Venue { get; set; }
public DateTime ResultDate { get; set; }
}
現在、私は次のものを持っています
var bestsGroups = from b in Model.CompetitorBests
group b by new { b.BestTypeName, b.BestTypeOrder }
into grp
orderby grp.Key.BestTypeOrder
select new
{
BestType = grp.Key.BestTypeName,
Results = grp.ToList()
};
しかし、これは明らかに DisciplineName によるグループ化を考慮していません。
私の出力コードは次のようなものです:
foreach (var bestsGroup in bestsGroups)
{
<h2>@bestsGroup.BestType</h2>
foreach (var result in bestsGroup.Results)
{
//i am guessing here i'll need another foreach on the discipline group....
<p>@result.DisciplineName</p>
<p>@result.ResultId </p>
}
}