根据查询中的列对结果系统进行评分 [英] Grading a result system based on a column from a query

查看:66
本文介绍了根据查询中的列对结果系统进行评分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



Please i have a project that i query the database using entity framework as my ORM. This is my query

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}







然后我查询我的结果,这样我就可以通过这样做来对它做一些操作< br $>





Then i query my result so that i can be able to do some operation on it by doing this

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





第二个查询的结果与gridview绑定,gridview在渲染时正确呈现。我的问题是我想在.MidTerm有界列之后在gridview上创建一个名为Rank的虚拟列,该列将显示搜索结果中每个人记录的位置。





这些是我的gridview专栏



The result of the second query is bounded to the gridview which renders properly as it is suppose to rendered. My problem is that i want to create a virtual column called Rank on the gridview after the .MidTerm bounded column that will display the position of each person record in the search result.


These are my gridview column

NAME       CA1      CA2      CA3     CA4     CA5    MIDTERM       RANK
James       50        50      60      40      60      52          3
Essty       100       50      50      50      50      60          2
Markus      100       40      50      60      50      60          2
Code        100       100     100     100     50      90          1





以上是gridview列的格式。我希望排名是一个基于学生的中期分数计算的虚拟列。代码VB得分为90所以他的排名是1等等。请不知道如何计算这个排名列和代码得到最高和最小。真的我需要帮助谢谢



Above is a format of the gridview columns. I want rank to be a virtual column that is calculated based on the midterm score of the students.Code VB scored 90 so his rank so be 1 and so on.Please i don't know how to calculate this rank column and the code to get the highest and the smallest.Really i need help thanks

推荐答案

这就是我最终使它工作的方式。

This is how i finally made it work.
Have a RANK field and pre-calculate it and bound it, something like:

        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,
               .RANK = -1}).ToList()
        dim sorted = secSubjectSearch.Select(function(n) n.MidTerm).Distinct().OrderByDescending(function(n) n).ToList()
        for each itm in secSubjectSearch
            itm.RANK = sorted.IndexOf(itm.MidTerm) + 1
        next



这个答案由@Rex在Stackoverflow上提供 http://stackoverflow.com/questions/19562115/how-to-create-a-virtual-column-on-a-gridview-based-on-a-特别是gridview-colu [ ^ ]


这篇关于根据查询中的列对结果系统进行评分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆