tags:

views:

88

answers:

2
+2  A: 

The key to this one is to include a self join on the team table, for team one and team two, like this:

var result = from bet in db.bet  
  join match in db.match on bet.matchid equals match.matchid
  join team1 in db.team on match.teamone equals team1.teamid 
  join team2 in db.team on match.teamtwo equals team2.teamid
  select new {bet.betid, bet.title, bet.description, match.location, match.begindate,   match.enddate, team1.name, team2.name};
Rhys Jones
+3  A: 

It looks like you already have the relationships defined. If you are using the designer, you should have existing entities in the generated classes.

var result = bet.Select( b => new {
                 BetID = b.betid,
                 Title = b.title, 
                 Description = b.description,
                 BeginDate = b.match.begindate, 
                 EndDate = b.match.enddate, 
                 TeamOneName = b.match.team_1.teamname, 
                 TeamTwoName = b.match.team_2.teamname 
              } );

Note that I'm only guessing at the association names. You should be able to figure out the names given to them by the designer.

tvanfosson
Yes, I agree. Much more readable than my solution also :)
Rhys Jones