Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I query a database with this linq to entities query and it returns a result where each particular person has three rows of data in the database. My aim is to make this three rows into one when displaying it in a gridview control or in a listview control.


VB
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}

From the above query the query results looks like this


SubRegNo  FirstName  Surname CA1  CA2  CA3  CA4  CA5  CA6  CA7 CA8  CA9  CA10  EXAM
     001       James       Osa    50  60   55   66   66   88   77  88   90   55    555
     002       James       Osa    90  44   66   77   56   99   55  66   77   78    878
     003       James       Osa    67  56   45   98   55   88   55  65   34   56    789
     007       Jamel       Psa    67  56   45   98   55   88   55  65   34   56    789
     008       Jamel       Psa    67  56   45   98   55   88   55  65   34   56    789
     009       Jamel       Psa    67  56   45   98   55   88   55  65   34   56    789

but this is what i what i want to achieve.


SubRegNo  FirstName  Surname CA1  CA2  CA3  CA4  CA5  CA6  CA7 CA8  CA9  CA10 EXAM    CA1  CA2  CA3  CA4  CA5  CA6  CA7 CA8  CA9  CA10 EXAM
    001       James       Osa    50  60   55   66   66   88   77  88   90   55    555

I want the three rows to appear as one row like what i explain above. I was told i can just group by in linq to entities but i still can get it to work. Please help out
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900