C#中的SQL到LINQ转换

时间:2010-08-15 23:06:51

标签: sql linq

任何人都可以在c#中告诉该查询的等效LINQ语法吗?

SELECT     Users.UserName, UserStatus.StatusTitle, UserStatus.StatusDetails
FROM UserStatus 
INNER JOIN  Users ON UserStatus.UserId = Users.UserID
where Users.userid=3 
OR users.userID in (
 SELECT     UserFriends.FriendId
 FROM Users 
 INNER JOIN UserFriends ON Users.UserID = UserFriends.UserId
 where Users.userid=3 )

1 个答案:

答案 0 :(得分:0)

(from status in UserStatus
join user in Users ON status.UserID equals user.UserID
where user.UserID == 3 ||
( from u in users
join friends in UserFriends on u.UserID equals friends.UserID where u.UserID == 3
select friends.FriendId).Contains(user.UserID)
select new {user.UserName, status.StatusTitle, status.StatusDetails});