Link to home
Start Free TrialLog in
Avatar of David Pickart
David PickartFlag for United States of America

asked on

LINQ Query Joining same table twice

I am having trouble with a LINQ query to return the name of the Home and Away team from the same table.  I have  schedule table with awayid and homeid.  In sql server it's easy to reference the teams table as teams and teams1 and get my data in same record.  I cannot figure out the LINQ code to produce same results.  

This brings in home team name.  How would I change it to also get away team from teams table.

 Dim curScores = From s In db.Schedules Join hteams In db.Teams On s.HomeID Equals hteams.Teamid
                Where s.Week = 3 And s.Season = "2014" Select Teamid = s.HomeID, HomeTeam = hteams.TeamName
SOLUTION
Avatar of Zberteoc
Zberteoc
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I understand the issue correctly, then one of Zberteoc's Join statements needs to reference the s.AwayID rather than both pointing to s.HomeID.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One correction the last line should be:

AwayTeam      =t2.TeamName