我有两个表帖和评论,我使用左连接到帖子和评论表但我得到多个相同的值,如何我可以删除重复值
public dynamic getalldetails()
{
GetAllPost =(
from user in dbContext.UserTable
join post in dbContext.PostTable on user.userId equals post.userID into PostGroup
from postdetails in PostGroup.DefaultIfEmpty()
join comment in dbContext.CommentTable on postdetails.PostId equals comment.PostedId into commentGroup
from commentdetails in commentGroup.DefaultIfEmpty()
orderby postdetails.CreatedAt descending
select new
{
userID = user == null ? 0 : user.userId,
name = user == null ? " " : user.Name,
postId = postdetails == null ? 0 : postdetails.postId
postedMessage = postdetails == null ? " " : postdetails.postedMessage
commentId = commentdetails == null ? 0 : commentdetails.commentId
commentMessage = commentdetails == null ? " " : commentdetails.commentMessage
}
}
).AsEnumerable();
}
我很有价值 1个帖子1个评论 2评论
1 post 1 comment
2 comment
2 post 1 comment
2 comment
2 post 1 comment
2 comment
我需要它像
1 post 1 comment
2 comment
2 post 1 comment
2 comment