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