根据查询中的列对结果系统进行评分

时间:2013-10-18 08:19:52

标签: entity-framework vb.net-2010

我有一个项目,我使用实体框架作为我的ORM查询数据库。这是我的查询

    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控件,它显示了它的设想方式。我的问题是我想从secSubjectSearch创建一个列,它将显示搜索结果中每个人记录的位置。例如.Total = CDbl(jamie.CA1 + jamie.CA2 + jamie.CA3 + jamie.CA4 + _                                            jamie.CA5 + jamie.CA6 + jamie.CA7 + jamie.CA8 + jamie.CA9 + jamie.CA10)结果是一个数值,其中invovles将列添加在一起。让我说这是

的结果
    .Total aspect=(56,56,78,58,90,98,99) i want a column that gives the position of each persons record like 99-1
                                                       98-2
                                                       90-3
                                                       78-4
                                                       58-5
                                                       56-6
                                                       56-6

就像基于搜索栏中的一种评分系统一样。请给我帮助。如果您需要更多解释,我会尝试更多来解释我的问题,谢谢

1 个答案:

答案 0 :(得分:0)

secSubjectSearch返回什么类型的对象?如果它是一个实体,因为它看起来应该是,它们是部分类 - 你可以创建另一个包含一个属性的部分类,该属性可以动态计算你的值,它只是一个虚拟列。