2009-04-24 4 views
2

사용자 지정 개체의 일반적인 목록을 가지고 있으며 특정 속성 값이 제외 목록에없는 개체로 해당 목록을 축소하려고합니다. 템플릿 ID가 제외 목록에없는 경우개체에 대한 LINQ -에 있지 않습니까?

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]'.

어떻게 난 단지 템플릿을 선택할 수 있습니다

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 

하지만 오류를 얻을 :

나는 다음과 같은 시도?

답변

5

Where 확장자 끝에 ToList() 확장을 추가하여 적절한 유형의 목록으로 다시 변환하십시오.

If usedTemplates IsNot Nothing Then 
    addIns = addIns.Where(Function(a) usedTemplates.Contains(a.TemplateID) = False) _ 
        .ToList() 
End If 
+0

감사합니다. : D – Nick

+0

감사합니다! C#에서 동일한 문제가 발생했을 때 ToList()가 핵심이었습니다! –

관련 문제