'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' 类型的表达式不可查询
Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable
我的class给我一个错误:
Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
我搜索了类似的问题,发现可能是 imports/references 的问题。然而,我想我导入了我需要的一切,但它仍然给我错误。
class 和项目参考如下:
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Dim Result As Integer
Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")
Private Function GetProcedureName(ByVal Name As String) As String
Dim Result As String = String.Empty
'this line gives the error
Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.@name = Name
For Each Elem As XElement In Elems
Result = Elem...<target>...<remote>...<source>.@name
Exit For
Next
Return Result
End Function
End Class
您没有 System.Linq
的导入,这意味着编译器找不到 LINQ to Objects,这是您尝试使用的 LINQ 实现。
只需将此添加到您的导入中:
Imports System.Linq
LINQ to XML 并不是真正的 LINQ 提供程序 - 它只是一个 XML API,它也适用于 LINQ to Objects。
我的class给我一个错误:
Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
我搜索了类似的问题,发现可能是 imports/references 的问题。然而,我想我导入了我需要的一切,但它仍然给我错误。
class 和项目参考如下:
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Dim Result As Integer
Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")
Private Function GetProcedureName(ByVal Name As String) As String
Dim Result As String = String.Empty
'this line gives the error
Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.@name = Name
For Each Elem As XElement In Elems
Result = Elem...<target>...<remote>...<source>.@name
Exit For
Next
Return Result
End Function
End Class
您没有 System.Linq
的导入,这意味着编译器找不到 LINQ to Objects,这是您尝试使用的 LINQ 实现。
只需将此添加到您的导入中:
Imports System.Linq
LINQ to XML 并不是真正的 LINQ 提供程序 - 它只是一个 XML API,它也适用于 LINQ to Objects。