我把课程简化为尽可能简单。以下是我的课程。
http
.authorizeRequests()
.antMatchers("/login").permitAll()
...
public class QuestionData
{
property QuestionID int {get; set;}
property Question String {get; set;}
property QuestionScore int {get; set;}
<!---Few More Properties ----!>
}
以下是我的样本数据
public class QuestionInfo
{
property QuestionID int {get; set;}
property Question String {get; set;}
property QuestionFinalScore int {get; set;}
property List<QuestionData> ListAchieved {get; set;}
}
在Question | QuestionID | QuestionScore
Q1 | 1 | 10
Q1 | 1 | 20
Q2 | 2 | 10
Q2 | 2 | -5
和Linq
Query
以下是我的输出
List<QuestionData> FinalSet = // Filled with Data Here
IEnumerable<QuestionInfo> datapoints = from f in FinalSet
group f by new { f.QuestionID, f.Question } into fGroup
select new QuestionInfo()
{
QuestionID = fGroup.Key.QuestionID
, Question = fGroup.Key.Question,
, QuestionFinalScore = fGroup.Sum(g => g.QuestionScore)
//, ListAchieved = This is where IDK what to do :(
};
现在,如果您看到我的班级Question | QuestionID | QuestionScore
Q1 | 1 | 30
Q2 | 2 | 5
,我需要将所有QuestionInfo
添加到我的问题QuestionData
媒体资源中,以便我可以在列表中显示{{1} }} ListAchieved
最终结束了它。
有人可以指出我需要做什么才能将所有这些项目添加到按Question
和QuestionFinalScore
分组的List<QuestionData>
属性
答案 0 :(得分:4)
我想你想这样做:
, ListAchieved = fGroup.ToList()
这会将一个组的所有项目放入列表中。