我有一个包含用户数据的表
Users(userID, name , email ,......)
我有另一个表,其中包含:
Userfriends(UserFriendID,Fk_UserSendReqID,FK_UserRecieveReqID,IsAccepted,....)
在 UserFriends 表中有两个外键将此表与用户表连接我想用 linq 编写一个查询来选择用户的朋友userId=2
我写了这个查询但它是错误的
var n = from u in DataContext.Context.Users
join uf in DataContext.Context.UsersFriends
on u.UserID equals uf.UserSendReqID
join uf2 in DataContext.Context.UsersFriends
on u.UserID equals uf2.UserRecieveReqID
where (uf.UserSendReqID == 2|| uf.UserRecieveReqID == 2)
&& uf.IsAccepted == true
select new
{
name = u.FirstName + " " + u.LastName
};