【发布时间】:2017-07-21 15:52:08
【问题描述】:
我有两个模型:
public class UserProfile {
public int Id { get; set; }
public virtual ICollection<UserProfile> Following { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public class Post {
public int Id { get; set; }
public virtual UserProfile { get; set; }
}
我想选择当前用户关注的用户的所有帖子。这基本上就像显示您在社交网站上关注的人的帖子的提要。我如何在 linq 中执行此操作?我收到了一个错误。
var following = CurrentUser.UserProfile.Following;
var posts = (from p in db.Posts
where following.Any(a=>a.Id == p.UserProfile.Id)
select new Post).ToList();
【问题讨论】:
-
错误是什么?
-
以上代码优先代码缺少某些内容。你能展示一下实际的数据库图吗?
标签: asp.net asp.net-mvc linq