0

linq to sql を使用して、フレンド ユーザー フレンド リストにないすべてのユーザーを見つけようとしています。現在、フレンドリストをシステム内のすべてのユーザーと比較しています。linq to sql を使用してこれを行うには、より良い方法が必要です。助けてくれてありがとう

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

2 に答える 2

2
  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;
于 2012-08-23T21:19:12.243 に答える
0

IEnumerable.Exceptを使用できます。

例:

var notIn = allUsersInSystem.Except(friends);

于 2012-08-23T20:53:14.590 に答える