0
請讓我有一個項目,我使用實體框架查詢數據庫作爲我的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添加列數值together.Let我說這是的
.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
像基於列的一種分級系統在search.Please我需要help.If結果你需要更多的解釋,我會盡力詳細說明我的問題,謝謝
請你指出我怎麼做你建議我忘了提到,我仍然是這個初學者。 –
你說你在使用EntityFramework;你是否首先生成了一個模型 - 一個edmx文件,看起來像一堆表示代表它們之間關係的表和行的塊?如果是這樣,那麼隨着.edmx文件,將會有一個.Designer.cs文件,其中包含定義表示這些表的實體的類的代碼。這些類被定義爲* partial *,這意味着如果在同一個項目中有另一個類,它也被定義爲* partial *,它們將合併爲一個。這使您可以將功能添加到模型外的實體[續] –
,以便在刷新模型時不會覆蓋新功能。所以你可以添加額外的屬性 - 列 - 從你已有的派生。即使你從不同的文件中獲得 - 只要所有東西都屬於同一個類。所以現在你需要弄清楚secSubjectSearch *是什麼類型的對象。最簡單的方法是斷開代碼並使用調試器告訴你它是什麼類,然後再去創建該類的另一部分片段。 –