gpt4 book ai didi

vb.net - 通过 LINQ 向树添加节点在运行时创建 "query operator not supported"

转载 作者:行者123 更新时间:2023-12-04 07:11:38 24 4
gpt4 key购买 nike

我正在努力解决 LINQ 问题。最终目标是使用从 LINQ to SQL( View )获取的数据加载树 View 。问题是当我尝试访问获取的数据时,它不断抛出“运行时不支持的查询运算符”。涉及的代码无外乎:

    Dim tasklistdata As New lqDataContext
Dim UserID As Integer

UserID = (From vwUser In tasklistdata.Operators _
Where vwUser.UserName Is Login.txtUsername.Text _
Select vwUser.OperatorID).Single

Dim lqHospitalList = From vwHospitalList In tasklistdata.SPM_Accounts _
Where vwHospitalList.OperatorID = UserID _
Order By vwHospitalList.CustomerName, vwHospitalList.Class _
Select vwHospitalList.CustomerName, vwHospitalList.Class, vwHospitalList.ClassCount, vwHospitalList.Charges

tvHospitalSelect.Nodes.Add(lqHospitalList(0).CustomerName)

如果我将代码更改为 lqHospitalList.First.CustomerName 它会按预期工作,但是将其更改为数组位置是问题出现的地方。请指导我指出我的逻辑缺陷所在。

最佳答案

Linq 查询不是列表,因此它们没有索引。要遍历所有项目,您可以像这样使用 foreach:

For Each hospital In lqHospitalList
tvHospitalSelect.Nodes.Add(hospital.CustomerName)
Next

如果要将查询转换为列表:
lqHospitalList.ToList

或数组:
lqHospitalList.ToArray

关于vb.net - 通过 LINQ 向树添加节点在运行时创建 "query operator not supported",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/260116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com