OK我有一個返回列表的基本查詢(的ObjectQuery,居然但我不認爲它很重要)LINQ的繼承和亞型(想篩選出基本類型)
我有一個基於約5亞型主要類型和我需要過濾它們。一切工作正常,直到我想要 結果是主要類型(不是子類)
基本上我有一個包含所有內容的查詢,然後我篩選出未在checkedbox列表中檢查的類型。 (asp.net)
可以說我有一個名爲任務的實體,並SubTask1和SubTask2從任務
Dim AllTasks As Objects.ObjectQuery(Of Demo.Task) = dbContext.CompletedTasks(ctx, anyID) 'calling a compiled query but it doesnt matter.
'It could be Dim AllTasks = from t in ctx.Tasks select t
For Each itm As ListItem In chkTaskTypeList.Items
If Not itm.Selected Then
Select Case itm.Value
Case "SubTask1"
'this works as expected, and eliminates tasks that are of the subtype Subtask1
AllTasks = From ti In AllTasks Where Not TypeOf ti Is SubTask1
Case "SubTask2"
'This also works as I want by filtering out the various sub types
AllTasks = From ti In AllTasks Where Not TypeOf ti Is SubTask2 AndAlso Not TypeOf ti Is SubTaskWhatever
Case "SubTask"
**'This works as expected, but not like I need. It removes all the types when what I really want is to remove**
**'The results that are of the base type but NOT the ones that are of a subtype**
AllTasks = From ti In AllTasks Where Not TypeOf ti Is SubTask
End Select
End If
Next
lvwHistory.DataSource = AllTasks
繼承如果我有亞型的限定日期數我大概可以這樣說(不TypeOf運算TI是SubTask和TypeOf TI是SubTask1),也... ,但我希望有一個更好的方法(和一個不打破如果一個新的子類型的頁面)
這不適用於L2E(嘗試它)。 – 2010-11-08 16:53:46
@Craig,現在當你這麼說的時候,我不需要試着去看看哪些部分不能很好地翻譯。 – 2010-11-08 17:59:43