我正在尝试获取User
列表FacebookFriend
以及当前用户尚未关注的列表(UserFollower
)。这是我试图使用的查询,但我仍然得到当前用户已经关注的用户。不知道下一步该做什么。
var fb = db.Members
.Include(i => i.User)
.Where(x => db.FacebookFriends.Where(y => y.UserID == CurrentUserID)
.Select(f => f.FacebookID)
.Contains(x.ProviderUserId)
&& !db.UserFollowers
.Select(f => f.FollowerID)
.Contains(x.UserID)
).Take(6).ToList();
FacebookID
与ProviderUserId
相同
FollowerID
是UserID
这是模特。
public class FacebookFriend
{
public int ID { get; set; }
public int UserID { get; set; }
public string FacebookID { set; get; }
public string Name { set; get; }
public User User { get; set; }
}
public class UserFollower
{
public int ID { get; set; }
public int UserID { get; set; }
public int FollowerID { get; set; }
[ForeignKey("UserID")]
public User User { get; set; }
[ForeignKey("FollowerID")]
public User Follower { get; set; }
}
Member
表
[Table("webpages_OAuthMembership")]
public class OAuthMembership
{
[Key, Column(Order = 0), StringLength(30)]
public string Provider { get; set; }
[Key, Column(Order = 1), StringLength(100)]
public string ProviderUserId { get; set; }
public int UserID { get; set; }
//public User User { get; set; }
[Column("UserID"), InverseProperty("OAuthMemberships")]
public User User { get; set; }
}
答案 0 :(得分:0)
看起来你的代码应该工作,但为了清楚起见,可以使用查询语法对其进行重组:
var fb =
(from m in db.Members
let friendIds =
from ff db.FacebookFriends
where ff.UserID == CurrentUserID
select ff.FacebookId
let followerIds =
from uf db.UserFollowers
select uf.FollowerID
where friendIds.Contains(m.ProviderUserId) && !followerIds.Contains(m.UserID)
select m)
.Take(6)
.ToList();