Slinky
Slinky

Reputation: 5832

Simple JOIN Syntax Not Working in Entity Framework

I am trying to add a join to an existing LINQ statement but my syntax is incorrect. I looked here for examples among other places yet, my construction is still not working. Visual Studio is throwing a hissy fit. Both datasets are in the context that I am trying to work with so not sure what I am doing wrong:

The red squiggly line under the "join" keyword produces the error "The type arguments cannot be inferred from the query" The "n" and "nc" aliases produce the error "Cannot resolve symbol"

enter image description here

My Original, working statement

 var query = from nc in context.NewClubs
                           where nc.ClubMasterCustomerId == clubMasterCustId
                           select nc;
               var results = query.Any();

What I am trying to do (Illustrated in SQL)

select nc.NewClubName,nc.Id from NewClub as nc
join NewClubBuilder ncb on ncb.NewClubId = nc.Id
where ncb.BuilderClubKeyNumber = 'K00841'

My translation from SQL to LINQ (Not working)

var query = from nc in context.NewClubs
            join n in context.NewClubBuilders on n.NewClubId equals nc.Id
            where nc.ClubMasterCustomerId == clubMasterCustId
            select nc;

            var results = query.Any();

Thanks

Upvotes: 2

Views: 1298

Answers (1)

Aducci
Aducci

Reputation: 26664

Swith the join properties, so nc.Id is first

join n in context.NewClubBuilders on nc.Id  equals n.NewClubId

Upvotes: 3

Related Questions