LINQ (join) question

  • Thread starter Thread starter bpsdgnews
  • Start date Start date
B

bpsdgnews

Hi,

I'm just starting with linq.

I can get data from collections in simple queries, but with a join I'm
still struggling.

See the code below.

I know for sure that in the Laps collection there are Laps with an
index equal to the FirstLapIndexes in the Runs collection. Still, the
result wil be a list with zero items.

Something I did wrong?


Dim Lijst = From Lap In m_gps.Laps _
Join Run In m_gps.Runs On Lap.Index Equals
Run.FirstlapIndex _
Select Lap.StartTime

MsgBox(m_gps.Runs.Count) 'Results in 26
MsgBox(m_gps.Laps.Count) 'Results in 142

MsgBox(Lijst.Count) 'Results in 0
 
Hi,

I'm just starting with linq.

I can get data from collections in simple queries, but with a join I'm
still struggling.

See the code below.

I know for sure that in the Laps collection there are Laps with an
index equal to the FirstLapIndexes in the Runs collection. Still, the
result wil be a list with zero items.

Something I did wrong?

Dim Lijst = From Lap In m_gps.Laps _
                Join Run In m_gps.Runs On Lap.Index Equals
Run.FirstlapIndex _
                Select Lap.StartTime

MsgBox(m_gps.Runs.Count) 'Results in 26
MsgBox(m_gps.Laps.Count) 'Results in 142

MsgBox(Lijst.Count) 'Results in 0


Found a way:

Changed my code to:

Dim Lijst = From Lap In m_gps.Laps _
From Run In m_gps.Runs _
Where (Lap.Index = Run.FirstLapIndex) _
Select Lap.StartTime


This works okay. Just looks a bit strange to me compared to regular
SQL.
 
Back
Top