1
即时通讯通过建立一个简单的社交网络来学习mvc。有点吸吮在这里。我试图创建2分贝查询。用列表查询数据库
第一个获取当前用户所关注的所有人的列表。
第二个获得这些用户的所有帖子列表。一整天都在尝试。请有人帮助我出去!
string id = //username of user we are finding friends for
//get all the people user is following
List<Friend> friendList = db.Freinds.Where(x => x.username == id).ToList();
//get all posts for those people
List<Post> postList = db.Posts.Where(x => friendList.Contains(x.Username)).ToList();
我的模型:
public class Post
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Int32 PostID { get; set; }
public string Username { get; set; }
public string Wallname { get; set; }
public DateTime PostDateTime { get; set; }
[Required(ErrorMessage = "{0} Is Required")]
[Display(Name = "Post Content")]
public String PostContent { get; set; }
public virtual List<Comment> Comments { get; set; }
}
public class Friend
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int friendID { get; set; }
public string username { get; set; }
public string following {get;set;}
}
在此先感谢。
完美,谢谢! – loveforfire33