vndotnet 2008 - Saving LINQ query result into variables.

  • Thread starter Thread starter plonk
  • Start date Start date
P

plonk

Hi
I have the following code which saves the result from a query into an
array. I want to be able to do some mathematic functions on the data,
but can't seem to figure out how to get it into variables of the
correct type.

*********

Dim myWinningTime = (From rrd In myScenario.MeetingInfos _
Join meet In
myScenario.RaceResultDatas On rrd.EventID Equals meet.EventID _
Where meet.RaceID = myEvent _
Select rrd.WinningTime,
rrd.RaceLength, meet.Dec, rrd.RailMetresOut)
Dim answer() = myWinningTime.ToArray

*********

Since the Array is of <anonymous type> I can't manipulate the data.

Ideally I would like to end up with 4 diferent declared variables,
each with their own type.

Please help as I am a bit of a noob :D

thanks PK
 
Perhaps this might get you on the right track.

Dim Items() As Item = _
{ _
New Book With {.ID = 1, .Price = 13.5, .Genre = "Comedy", .Author = "Jim
Bob"}, _
New Book With {.ID = 2, .Price = 8.5, .Genre = "Drama", .Author = "John
Fox"}, _
New Movie With {.ID = 3, .Price = 22.99, .Genre = "Action", .Director =
"Phil Funk"}, _
New Movie With {.ID = 4, .Price = 13.4, .Genre = "Action", .Director =
"Eddie Jones"} _
}

Dim ItemQueryOne = From Item In Items _
Where Item.Price > 9.99 _
Order By Item.ID _
Select Price = Item.Price, Item.ID, Type =
Item.Genre

Dim temp As Integer
For Each Item In ItemQueryOne
temp = Item.ID + 1
Console.WriteLine("ID +1 {0} Price increase {1} original price {2}", _
temp, Item.Price + 2.3, Item.Price)
Next

...............

Public Class Item
Private mID As Integer
Private mPrice As Double
Private mGenre As String
Public Property Genre() As String
Get
Return mGenre
End Get
Set(ByVal value As String)
mGenre = value
End Set
End Property
Public Property ID() As Integer
Get
Return mID
End Get
Set(ByVal value As Integer)
mID = value
End Set
End Property
Public Property Price() As Double
Get
Return mPrice
End Get
Set(ByVal value As Double)
mPrice = value
End Set
End Property

End Class
Public Class Book
Inherits Item

Private mAuthor As String
Public Property Author() As String
Get
Return mAuthor
End Get
Set(ByVal value As String)
mAuthor = value
End Set
End Property
End Class
Public Class Movie
Inherits Item

Private mDirector As String
Public Property Director() As String
Get
Return mDirector
End Get
Set(ByVal value As String)
mDirector = value
End Set
End Property

End Class
 
Back
Top