0
我有一個Exam
表條件計,然後ExamResults
其中包括特定考試的所有問題。此表將包含的問題,選擇答案,以及AnswerPower,表示如果答案是正確與否:的GroupBy和使用LINQ
- (指正確的),
- (指錯了),
- NULL(表示未答覆,將被視爲錯誤)。
我試圖得到Count
由章節分組的特定考試的錯誤答案。
下面會給我按章分組答案的數量,但我不知道哪兒來設定條件只計算錯誤的答案它可以簡單地AnswerPower!=1
var query = ex.ExamResults
.GroupBy(p => new
{
p.Question.Chapter.ChapterName,
p.AnswerPower
})
.Select(g => new
{
g.Key.ChapterName,
Mistakes = g.Count()
});
「Where」中沒有直接的'p.AnswerPower',我想你的意思是'p.Key.AnswerPower!= 1' – omarmallat