LINQ (join) question

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
 
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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top