indy500fan
asked on
Need help with LINQ, doing a double join.
Friends,
I am trying to create a LINQ qry in C# that has a double join; however, mine isn't quite right.
Here is the SQL syntax:
Declare @RunID int
Set @RunID =23
Select
r.No,
st.EntryTime,
st.ExitTime,
st.SectionID,
st.ShortName,
st.SectionSpeed,
st.SectionTime,
spo.SectionKey,
spo.SectionID,
st.Lap
From SectionTimes st inner join Results r
on st.RunID=r.RunID
AND st.ResultItemID=r.ResultID
inner join SectionPreferredOrder spo
on st.SectionID = spo.SectionID
WHERE st.RunID=@RunID and st.Lap < 65536
and st.shortname like 'S%'
and (st.Flag=1 or st.Flag=2 or st.Flag=4) and st.Lap >=0
And here is what I have for LINQ:
var query = from st in dc.Sectiontimes
join r in dc.Results on new { st.RunID, st.ResultID } equals new { r.RunID, r.ResultID }
join spo in dc.SectionPreferredOrders on new { st.SectionID } equals new { spo.SectionID1 }
where st.RunID == RunId && st.Lap < 65536 && st.ShortName.StartsWith("S ") && (st.Flag == 1 || st.Flag == 2 || st.Flag == 4)
&& st.Lap >= 0
orderby st.EntryTime, st.ExitTime, st.SectionID
select new
{
r.No,
st.EntryTime,
st.ExitTime,
st.SectionID,
st.ShortName,
st.SectionSpeed,
st.SectionTime1,
st.Lap,
spo.SectionID1,
spo.SectionKey
};
I however am getting an error on the line:
join spo in dc.SectionPreferredOrders on new { st.SectionID } equals new { spo.SectionID1 }
join is underlined and the error is:
Error 15 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
Any ideas how to fix it?
Thanks in advance!
Best Regards,
Eric
I am trying to create a LINQ qry in C# that has a double join; however, mine isn't quite right.
Here is the SQL syntax:
Declare @RunID int
Set @RunID =23
Select
r.No,
st.EntryTime,
st.ExitTime,
st.SectionID,
st.ShortName,
st.SectionSpeed,
st.SectionTime,
spo.SectionKey,
spo.SectionID,
st.Lap
From SectionTimes st inner join Results r
on st.RunID=r.RunID
AND st.ResultItemID=r.ResultID
inner join SectionPreferredOrder spo
on st.SectionID = spo.SectionID
WHERE st.RunID=@RunID and st.Lap < 65536
and st.shortname like 'S%'
and (st.Flag=1 or st.Flag=2 or st.Flag=4) and st.Lap >=0
And here is what I have for LINQ:
var query = from st in dc.Sectiontimes
join r in dc.Results on new { st.RunID, st.ResultID } equals new { r.RunID, r.ResultID }
join spo in dc.SectionPreferredOrders on new { st.SectionID } equals new { spo.SectionID1 }
where st.RunID == RunId && st.Lap < 65536 && st.ShortName.StartsWith("S
&& st.Lap >= 0
orderby st.EntryTime, st.ExitTime, st.SectionID
select new
{
r.No,
st.EntryTime,
st.ExitTime,
st.SectionID,
st.ShortName,
st.SectionSpeed,
st.SectionTime1,
st.Lap,
spo.SectionID1,
spo.SectionKey
};
I however am getting an error on the line:
join spo in dc.SectionPreferredOrders on new { st.SectionID } equals new { spo.SectionID1 }
join is underlined and the error is:
Error 15 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
Any ideas how to fix it?
Thanks in advance!
Best Regards,
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER