1

I have two table post and comment, i am using left join to both post and comment table but i am getting the multiple same value,how to i can remove duplicate value

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();
}

I am getting value like 1 post 1 comment 2 comment

 1 post 1 comment
        2 comment

 2 post 1 comment
        2 comment

 2 post 1 comment
        2 comment

I need it like

 1 post 1 comment
        2 comment
 2 post 1 comment
        2 comment
Doug Amos
  • 4,243
  • 1
  • 22
  • 23
Nagaraj M
  • 387
  • 1
  • 5
  • 16

0 Answers0