2

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'.

1
  • I think you copy pasted, so I can see an 'eqals' that maybe is 'equals' Commented Jul 18, 2012 at 9:03

1 Answer 1

9

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();
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that was simple enough. I guess ive been doing TSQL for so long I did'nt notice. Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.