Pass Linq query result with Intellisense?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Is it possible to pass a LINQ query result to a Sub and not lose
Intellisense to the Fields returned.

Example:

Public Sub DoPriceListQuery()

Dim dbCus As New DataAPDataContext
Dim Price = (From c In dbCus.tblPriceLists _
Where c.Disabled = False _
And c.OwnerID = 1 _
Select c).ToArray


'have intellisense to fields returned in query
EditWeb(Price)


dbCus.SubmitChanges()
End Sub

Private Sub EditWeb(ByRef Price As Array)

For Each p in Price
With p

'lose Intellisense here but code works

End With
Next

End Sub
 
John said:
Is it possible to pass a LINQ query result to a Sub and not lose
Intellisense to the Fields returned.
Yes

Example:

Public Sub DoPriceListQuery()

Dim dbCus As New DataAPDataContext
Dim Price = (From c In dbCus.tblPriceLists _
Where c.Disabled = False _
And c.OwnerID = 1 _
Select c).ToArray

which would result in a strong list of said:
'have intellisense to fields returned in query
EditWeb(Price)


dbCus.SubmitChanges()
End Sub

Private Sub EditWeb(IEnumerable<Price> as prices)

For Each p in Price
With p

ForEach var p in prices
with p

And you should have intellisense on the 'price' object in prices now.
'lose Intellisense here but code works

End With
Next

End Sub


You're using VB, and I do it with C#. So I'll assume you can use a "var" in
VB.NET like you can in C#. Also, some of my usage of VB is not 100% anymore
but the usage of List<t> and IEnumerable<t> are the same between the two
languages.
 
Thanks to all
this worked
Private Sub EditWeb(ByRef Price As IEnumerable(Of tblPriceList)
End Sub
 
Back
Top