2016-12-01 7 views
0

ここで私は全ての投稿とコメントを取得していますが、問題は私がデバッグしたときにGetAllPostに2つ以上のデータが表示されますが、その、一度にすべてのデータを返さないのはなぜたびに、あなたがそれによって前に開催されたものは何でも捨て、GetAllPostに代入している、ループを通って...オブジェクトのリストを追加して返す方法

public dynamic getalldetails(int friendsid) 
{ 
    var GetAllPost = (dynamic)null; 
    FriendsId =dbContext.Usertable.where(u=>u.userID==friendsid).tolist(); 

    if(FriendsId!=null) 
    foreach(var item in FriendsId) 
    { 
     GetAllPost = (from post in db.Posts.where(item.userID==post.userID).ToList() 
         orderby post.PostedDate descending 
         select new 
         { 
          Message = post.Message, 
          PostedBy = post.PostedBy, 
          PostedByName = post.UserProfile.UserName, 
          PostedByAvatar =imgFolder + (String.IsNullOrEmpty(post.UserProfile.AvatarExt) ? defaultAvatar : post.PostedBy + "." + post.UserProfile.AvatarExt), 
          PostedDate = post.PostedDate, 
          PostId = post.PostId, 
          PostComments = from comment in post.PostComments.ToList() 
              orderby comment.CommentedDate 
              select new 
              { 
               CommentedBy = comment.CommentedBy, 
               CommentedByName = comment.UserProfile.UserName, 
               CommentedByAvatar = imgFolder +(String.IsNullOrEmpty(comment.UserProfile.AvatarExt) ? defaultAvatar : comment.CommentedBy + "." + comment.UserProfile.AvatarExt), 
               CommentedDate = comment.CommentedDate, 
               CommentId = comment.CommentId, 
               Message = comment.Message, 
               PostId = comment.PostId 
              } 
         }).AsEnumerable(); 

    } 
    return GetAllPost; 
} 
+0

あなたのコードを読むのはとても難しいです。あなたは適切なシンボルを含めることができますか?そしてドット? –

+1

コードは正しくコンパイルされませんので、最初に修正してください。私たちが助けてくれるのをやめさせたら、私たちの助けを期待しないでください。 –

答えて

0

を助ける必要は得ていないのです。あなたは、これらの行に沿った何かの投稿を蓄積する必要があります:

ArrayList GetAllPost = new ArrayList(); 
... 
foreach (var item in FriendsId) 
{ 
    GetAllPost.AddRange(from post in 
     // Your LINQ code 
     ...); 
} 

return GetAllPost; 
関連する問題