Multiple Join in Entity Framework

11,342

Exactly what the error is saying

p.PhoneNumberId equals link.PhoneNumberId 

should be

link.PhoneNumberId equals p.PhoneNumberId

Full code

var query = (from u in myEntities.Users
  join link in myEntities.linkUserPhoneNumbers on u.UserId equals link.UserId 
  join p in myEntities.PhoneNumbers on link.PhoneNumberId equals p.PhoneNumberId
  where u.UserName == Username && u.Password == Password
  select u).ToList();
Share:
11,342
Welsh King
Author by

Welsh King

Updated on June 05, 2022

Comments

  • Welsh King
    Welsh King almost 2 years

    I have the following query in TSQL

    select * from users 
    inner join linkUserPhoneNumber on users.UserId = linkUserPhoneNumber.UserId
    INNER JOIN PhoneNumber ON PhoneNumber.PhoneNumberId =
        linkUserPhoneNumber.PhoneNumberId
        where UserName = 'superuser' and password ='password'
    

    I have the following query in Entity Framework

    var query = (from u in myEntities.Users
      join link in myEntities.linkUserPhoneNumbers on u.UserId equals link.UserId 
      join p in myEntities.PhoneNumbers on p.PhoneNumberId equals link.PhoneNumberId
      where u.UserName == Username && u.Password == Password
      select u).ToList();
    

    When I try to compile it, I get

    Error 3 The name 'p' is not in scope on the left side of 'equals'. Consider swapping the expressions on either side of 'equals'.
    Error 4 The name 'link' is not in scope on the right side of 'equals'. Consider swapping the expressions on either side of 'equals'.

  • Welsh King
    Welsh King almost 12 years
    thanks, that was simple enough. I guess ive been doing TSQL for so long I did'nt notice. Thanks again