我有一个表 Assessment,其中包含 {rated,rater,assessment_id} 另一个表是 Category_Scores,其中包含 {score,assessment_id}。我正在尝试按评分分组,按评分分组。目前我有这个 LINQ 查询
var query = (from a in db.Assessments
join u in db.Users on a.rated equals u.user_id
join u2 in db.Users on a.rater equals u2.user_id
join tm in db.Team_Members on u.user_id equals tm.user_id
join t in db.Teams on tm.team_id equals t.team_id
join c in db.Category_Scores on a.assessment_id equals c.assessment_id
join cat in db.Categories on c.category_id equals cat.category_id
group new KyubiViewModel
{
rated = u.firstName + " " + u.lastName,
rater = u2.firstName + " " + u2.lastName,
score = c.score,
category_name = cat.name,
categoryid = c.category_id,
}
by new { rated = u.firstName + " " + u.lastName,rater = u2.firstName + " " + u2.lastName }).ToList();
这导致
{ rated = John Will, rater = Jess James}
10 [Math]
10 [Science]
{ rated = John Will, rater = Mike Rand}
7 [Math]
7 [Science]
我希望它看起来像
{ rated = John Will }
rater: Math Science
Jess James 10 10
Mike Rand 7 7
{ rated = Jess James }
rater: Math Science
John Will 9 9
Mike Rand 7 7
这是我的看法
<table>
@foreach (var group in Model)
{
<tr>
<td>@group.Key </td>
</tr>
foreach (var m in group)
{
<tr>
<td>@m.score - [@m.category_name]</td>
</tr>
}
}
</table>
任何帮助,将不胜感激。
在 ChaseMedallion 的帮助下,我能够在我看来做到这一点
{ rated = John Will }
rater:
Jess James 10[Math]
Jess James 10[Science]
Mike Rand 7[Math]
Mike Rand 7[Science]
如果可能的话,我希望这样
{ rated = John Will }
rater: Math Science
Jess James 10 10
Mike Rand 7 7