使用实体框架时,将多行查询结果转换为一行

时间:2013-10-29 12:01:01

标签: vb.net entity-framework gridview

我有一个查询,返回学生在文本中得分的标记。

     Dim subjectSearch = From subSearch In DemoSchool.EssenceSubjectRegistrations Where subSearch.Session = drpSession.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,

                                         .CA4 = subSearch.CA4 }

上面的查询在绑定到gridview时返回这样的结果。每个学生在数据库中总共有三条记录。

    SubjectRegSN   FirstName  Surname  CA1  CA4
     101            James       Osa     45   65
     102            James       Osa     76   98
     103            James       Osa     56   76   
     105            Fames       Dan     45   65
     106            Fames       Dan     76   98
     107            Fames       Dan     56   76  

但我想要这种性质的东西

    SubjectRegSN   FirstName  Surname  CA1  CA4 CA1  CA4 CA1  CA4
        1           James      Osa     45    65  76   98  56  76
        2           Fames      Dan     45    65  76   98  56  76

subjectSN是从中选择的表EssenseSubjectRegistration的数据库中的主键。请帮忙。

0 个答案:

没有答案