0

您好,请在 linq to 实体方面遇到问题。我正在研究一个学校管理系统。我可以从数据库中生成每个学生的记录和学生的分数,这被绑定到一个 gridview 控件。下面是我用来生成学生分数的代码

    Dim subjectSearch = From subSearch In DemoSchool.EssenceSubjectRegistrations Where subSearch.Session = drpSession.SelectedItem.Text _
                    AndAlso subSearch.Term = drpTerm.SelectedItem.Text AndAlso subSearch.RealClass.ClassSN = findClassSN.FirstOrDefault AndAlso _
                     subSearch.SubjectCode = drpSubject.SelectedValue _
                     Select New With {.SubjectRegSN = subSearch.SubjectRegSN,
                                     .FirstName = subSearch.Student.FirstName,
                                     .Surname = subSearch.Student.Surname,
                                      .CA1 = subSearch.CA1,
                                       .CA2 = subSearch.CA2,
                                       .CA3 = subSearch.CA3,
                                       .CA4 = subSearch.CA4,
                                       .CA5 = subSearch.CA5,
                                       .CA6 = subSearch.CA6,
                                       .CA7 = subSearch.CA7,
                                       .CA8 = subSearch.CA8,
                                       .CA9 = subSearch.CA9,
                                       .CA10 = subSearch.CA10,
                                     .Exam = subSearch.Exam}

这样做之后,我对我的结果执行这个查询,以通过这样做来计算一些虚拟列的结果

    Dim secSubjectSearch = (From jamie In subjectSearch Select jamie).ToList() _
                          .Select(Function(jamie) New With {.SubjectRegSN = jamie.SubjectRegSN,
                          .FirstName = jamie.FirstName,
                          .Surname = jamie.Surname,
                           .CA1 = jamie.CA1,
                            .CA2 = jamie.CA2,
                            .CA3 = jamie.CA3,
                            .CA4 = jamie.CA4,
                            .CA5 = jamie.CA5,
                            .MidTerm = CDbl(jamie.CA1 + jamie.CA2 + jamie.CA3 + jamie.CA4 + jamie.CA5) / 5,
                            .CA6 = jamie.CA6,
                            .CA7 = jamie.CA7,
                            .CA8 = jamie.CA8,
                            .CA9 = jamie.CA9,
                            .CA10 = jamie.CA10,
                             .Total = CDbl(jamie.CA1 + jamie.CA2 + jamie.CA3 + jamie.CA4 + _
                                      jamie.CA5 + jamie.CA6 + jamie.CA7 + jamie.CA8 + jamie.CA9 + jamie.CA10),
                           .Exam = jamie.Exam})

此结果与正确显示的网格视图有关。我的问题是每个学生对每个科目都有三个记录(科目分数在一年内记录三次,分别是第一学期第二学期和第三学期),并且该记录显示为三个单独的行为每个学生。我想要一种情况,我可以将每个学生记录只放在一行上,这样每个学生在 gridview 中只有一行而不是三行。我真的需要资深专业人士的帮助,自从过去五天以来,我一直在拔头发。一如既往地感谢您的帮助。

4

0 回答 0