tags:

views:

41

answers:

1

Can anybody tell the equivalent LINQ syntax for this query in c#?

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 )
A: 
(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});
Femaref
Instead of `.Any(f => f == user.UserID)`, I think `.Contains(user.UserID)` is better, as it more closely matches the SQL.
Gabe
yup, that's better.
Femaref