2
我有自定義對象的一個泛型列表,並希望減少對對象列表,特定屬性值不在排除列表。LINQ到對象 - 這難道不是嗎?
我曾嘗試以下:
Private Sub LoadAddIns()
// Get add-in templates
Dim addIns = GetTemplates(TemplateTypes.AddIn)
// Get the current document
Dim sectionId As String = CStr(Request.QueryString("sectionId"))
Dim docId As Integer = CInt(Split(sectionId, ":")(0))
Dim manual = GetTempManual(docId)
Dim content As XElement = manual.ManualContent
// Find which templates have been used to create this document.
Dim usedTemplates = (From t In content.<header>.<templates>.<template> _
Select CInt(t.<id>.Value)).ToList
// Exclude add-ins that have already been used.
If usedTemplates IsNot Nothing Then
addIns = addIns.Where(Function(a) usedTemplates.Contains(a.TemplateID) = False)
End If
// Bind available add-ins to dropdown
With ddlAddIns
.DataSource = addIns
.DataTextField = "Title"
.DataValueField = "TemplateID"
.DataBind()
.Items.Insert(0, New ListItem("[select an add-in]", 0))
End With
End Sub
,但得到的錯誤:
System.InvalidCastException: Unable to cast object of type 'WhereListIterator
1[MyApp.Classes.Data.Entities.Template]' to type 'System.Collections.Generic.List
1[MyApp.Classes.Data.Entities.Template]'.
我怎麼可以只選擇模板,其中模板ID不排除列表?
點上,謝謝! :d – Nick 2009-04-24 15:22:01