我在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'
我在实体框架中有以下查询
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();
当我尝试编译它时,我得到
错误3名称“ p”不在“等于”左侧的范围内。考虑在“等号”的任一侧交换表达式。 错误4名称“链接”不在“等于”右侧的范围内。考虑在“等号”的任一侧交换表达式。
错误究竟在说什么
p.PhoneNumberId equals link.PhoneNumberId
应该
link.PhoneNumberId equals p.PhoneNumberId
完整的代码
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();