Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello please have run into problems with linq to entities. Am working on a school management system.I can generate from the database the record of each student and the student scores from and this is binded to a gridview control. Below is the code i use in generating the student scores

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

After doing this i peform this query on my result to calculate the result of some virtual columns by doing this
VB
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})

This result is bounded to a gridview that displays properly.My problem is that each student have three records for each subjects (subjects scores are recorded three times in a year as first term second term and third term) and this records appears as three seperate rows for each student. I want a situation where i can put each student record on only one row so that each student will have just one row in the gridview and not three rows.
I really need help from senior professionals have been pulling out my hair since the past five days. Thanks as always as you 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