我想在 Twitter 上找到我没有关注的关注者的关注者。
为此,我有一个名为 Follow 的表,其中包含三个列 ID、Follower_iD 和 Follower_iD
我的代码如下:
var userIDs = database.Followings.Where(u => u.Follower_id == MY.Id);
foreach (var userID in userIDs)
{
var secondUserIDs = database.Followings.Where(u => u.Follower_id == userID.Following_id).Except(userIDs);
尽管我写了 .Except(userIDs) 是为了消除我关注的人,但输出包括我已经关注的记录。
为了更好地解释我的问题,这里是一个例子:
假设我的 id 是 10。
并且在数据库中有记录:
follower_id following_id
10 11
10 12
10 13
10 14
14 12
14 13
14 15
所以问题是,由于我同时关注 12 和 13,因此无需在查询中返回 (14,12) 和 (14, 13) 对。