I've been having a heck of a time getting this query right, so I'm hoping that StackOverflow can point me in the right direction.
I have three tables:
- Territories (TerritoryId, TerritoryName, etc)
- UserTerritories (Just a gerrund)
- Users (UserId, UserName, StatusId)
I need to get all the Territories that have one or more Users with a StatusId of (let's say) 3.
All I've really been able to get to compile is linking up all the tables :(
IEnumerable<Territory> territories = (from t in db.Territories
join uXt in db.User_x_Territories on t.TerritoryId equals uXt.UserID into tJoin
from uXt in tJoin.DefaultIfEmpty()
join u in db.Users on uXt.UserID equals u.Id into uJoin
from u in uJoin.DefaultIfEmpty()
select t);
Can anyone help me out? All I've been able to find online are fairly basic examples.