여기에서 friendID에 대한 모든 게시물과 댓글이 잘 작동하고 있습니다. 내 문제는 디버그 할 때 GetAllPost에 2 개 이상의 데이터가 표시되지만 마지막 데이터 만 반환합니다. 한 번에 모든 데이터를 반환하지 않는 이유를 알 수 없습니다. 도움이 필요하다..
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;
}
루프를 통과 할 때마다에 할당 GetAllPost
하므로 이전에 보유한 모든 항목을 버립니다. 다음 줄을 따라 게시물을 축적해야합니다.
ArrayList GetAllPost = new ArrayList();
...
foreach (var item in FriendsId)
{
GetAllPost.AddRange(from post in
// Your LINQ code
...);
}
return GetAllPost;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다