Reputation: 569
I am trying to get my head around a LINQ issue. The ultimate goal is to load tree view with data acquired from LINQ to SQL (view). The issue is when I try to access the data acquired it keeps throwing a "query operator not supported during runtime". The code involved is no more than:
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)
if I were to change the code to lqHospitalList.First.CustomerName it works as expected, however changing it to array position is where the issue arises. Please direct me to where my flaw in logic is.
Upvotes: 2
Views: 287
Reputation: 71866
Linq querys are not lists, so they don't have an index. To iterate over all the items you can use a foreach like so:
For Each hospital In lqHospitalList
tvHospitalSelect.Nodes.Add(hospital.CustomerName)
Next
If you want to convert the query to a list:
lqHospitalList.ToList
or array:
lqHospitalList.ToArray
Upvotes: 3