C# linq到sql,其中不在
我正在尝试使用linq to sql查找不在好友用户好友列表中的所有用户。现在我正在将friendslist与系统中的所有用户进行比较。使用LINQtoSQL一定有更好的方法。谢谢你的帮助C# linq到sql,其中不在,c#,linq-to-sql,C#,Linq To Sql,我正在尝试使用linq to sql查找不在好友用户好友列表中的所有用户。现在我正在将friendslist与系统中的所有用户进行比较。使用LINQtoSQL一定有更好的方法。谢谢你的帮助 // Comparing this to list to see who does not exist. // What I would like to do is just use one statement // to get the list of non friend users var friend
// Comparing this to list to see who does not exist.
// What I would like to do is just use one statement
// to get the list of non friend users
var friends = (from x in db.FriendsLists
where
(x.TheUser == GlobalVariables.User.ID) ||
(x.TheFriend == GlobalVariables.User.ID)
select x).ToList();
var allUsersInSystem = (from x in db.Users select x).ToList();
你可以用
例如:
var notIn=allUsersInSystem.Except(朋友)代码>这个问题的可能重复实际上是关于LINQ到实体的问题,而不是LINQ到SQL的问题。这可能也适用于LINQtoSQL。。。
var friends = (from x in db.FriendsLists
where
(x.TheUser == GlobalVariables.User.ID) ||
(x.TheFriend == GlobalVariables.User.ID)
select x.UserID).ToList();
var notInFriendList = from nf in db.Users
where !friends.Contains(nf.UserID)
select nf;