gpt4 book ai didi

c# - Entity Framework 中的多重连接

转载 作者:行者123 更新时间:2023-12-03 20:30:10 24 4
gpt4 key购买 nike

我在 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'

我在 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();

当我尝试编译它时,我得到了

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

最佳答案

错误到底是什么意思

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();

关于c# - Entity Framework 中的多重连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11537757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com