我有一個表的評估,其中包含{額定,評價者,assessment_id}另一個表是Category_Scores含有{得分,assessment_id}。我試圖按照評分者的評分組來分組評分,分組評分。目前,我有這個LINQ查詢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
感謝您的答覆,我想在視圖中顯示它,但是難以產生結果,我應該如何在視圖中執行循環? –
@shinratensei:假設你的模型的類型是IEnumerable>,你的當前視圖代碼應該在給定屬性名稱更改時正常工作。你遇到了什麼錯誤? –
ChaseMedallion
我的薄霧先生,我忘了添加我的viewmodel後選擇新的。這將評估者按照我想要的評分進行分組,但是我無法在視圖中顯示正確的數據位置。我將編輯我的帖子,向您展示我目前擁有的視圖 –