This statement won’t compile:
query = from g in context.GridViews
join f in context.GridViewFavorites on g.ID equals f.GridViewID into gf
where g.GridTypeID == id && ( g.IsShared == true || g.RepID == me.clsRep.OID)
&& f.RepID == me.clsRep.OID
select g;
The compiler error is this (and it’s underlining the last part of the where clause:
The name ‘f’ does not exist in the current context
It’s logical SQL counterpart would be:
declare @RepID int
declare @GridTypeID int
select @RepID=15, @GridTypeID=5
select g.*,f.*
from
GridViews g
left outer join GridViewFavorites f on f.GridViewID = g.ID
where
g.GridTypeID = @GridTypeID and (g.IsShared = 1 or g.RepID == @RepID)
and f.RepID == @RepID
NOTE: per @hdv ‘s good catch the SQL sample should actually be:
select g.*,f.*
from
GridView g
left outer join GridViewFavorite f on f.GridViewID = g.ID and f.RepID = @RepID
where
g.GridTypeID = @GridTypeID and (g.IsShared = 1 or g.RepID = @RepID)
It’s the “into” part of your join – once you’ve joined “into” a group, the join variable (
fin this case) is out of scope – you’ve got to usegfinstead. Alternatively, given that you’re not actually usinggfin your query at all, maybe you should just get rid of theinto gfpart entirely so it’s a normal join instead of a group join.However, that won’t give you a left outer join. If you want a left outer join, you might want: