+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / BlogPost.Comments.Count is always 0

BlogPost.Comments.Count is always 0

9 posts, 1 answered
  1. Raymond Dowe
    Raymond Dowe avatar
    37 posts
    Registered:
    10 Mar 2010
    29 Feb 2012
    Link to this post
    I'm trying to build a custom widget which shows the "most discussed" blog posts. This will work by counting the number of comments and displaying them ordered.

    Whenever use the fluent api to get blog posts, the .Comments.Count property is always 0. I don't understand what I'm doing wrong.

    My site has 2 blogs, with 7 posts, 2 of which have comments.

    System.Collections.Generic.List<BlogPost> blogposts = App.WorkWith().BlogPosts().Where(b => b.Status == ContentLifecycleStatus.Live).Get().ToList();
      
    foreach (BlogPost blogpost in blogposts)
    {
        BlogPost bp = App.WorkWith().BlogPost(blogpost.OriginalContentId).GetLive().Get();
        int comment_count = bp.Comments.Count;
    }
  2. Matthias
    Matthias avatar
    10 posts
    Registered:
    30 Jul 2009
    01 Mar 2012
    Link to this post
    Hi Raymond,

    i think you don't do anything wrong. Here is what the Sitefinity Support told me a few days ago: "...it seems that Comments.Count property is not working as expected...".
    You have to use some kind of workaround. Maybe retrieve all comments for that blog and then go on with your specific tasks:
    BlogsManager blogsManager = BlogsManager.GetManager();
    var allComments = blogsManager.GetComments().Where(c => c.ParentGroupIds.Contains(MyBlogID)).ToList();

    HTH
    Matthias
    Answered
  3. Grace Hallwachs
    Grace Hallwachs avatar
    144 posts
    Registered:
    03 Nov 2014
    02 Mar 2012
    Link to this post
    Hello Raymond,

    Please let us know if your issue was resolved. Thanks so much.

    Regards,
    Grace Hallwachs
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    02 Mar 2012
    Link to this post
    Hi Grace,

    I also used the same approach as Matthias. But what we of course want to know is if we can use the Comments property from the BlogPostItem?

    Is it a bug that it doesn't work, or is it by design?

    Thanks,
    Daniel
  5. Raymond Dowe
    Raymond Dowe avatar
    37 posts
    Registered:
    10 Mar 2010
    02 Mar 2012
    Link to this post
    Thanks Matthias, that worked for me. For anyone else to come across this, my working code is:

    System.Collections.Generic.List<BlogPost> blogposts = App.WorkWith().BlogPosts().Where(b => b.Status == ContentLifecycleStatus.Live).Get().ToList();
     
    foreach (BlogPost blogpost in blogposts)
    {
        BlogsManager blogsManager = BlogsManager.GetManager();
        var allComments = blogsManager.GetComments().Where(c => c.ParentGroupIds.Contains(blogpost.Id)).ToList();
    }

  6. Grace Hallwachs
    Grace Hallwachs avatar
    144 posts
    Registered:
    03 Nov 2014
    07 Mar 2012
    Link to this post
    Hello Daniel,

    Yes, you can use the Comments property from the BlogPostItem. I have included a code sample that retrieves all the live blog posts and then counts all the comments.

    public void GetBlogsComments()
           {
            
               BlogsManager blogsManager = BlogsManager.GetManager();
      
               //Get the master version.
               BlogPost blogPost = blogsManager.GetBlogPosts().Where(b => b.Status == ContentLifecycleStatus.Live).FirstOrDefault();
      
               if (blogPost != null)
               {
                   // Get the live version
                   blogPost = blogsManager.Lifecycle.GetLive(blogPost) as BlogPost;
      
                   // Get the comment
                   var aaa = blogsManager.GetComments().ToList();
      
                   aaa.Count();
               }

    I have also included a link to our documentation to query comments and how to manage blog posts for your reference.

    Please let us know if you have anymore questions. Thank you so much.

    Regards,
    Grace Hallwachs
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    14 Apr 2012
    Link to this post
    Is this bug going to be fixed? We are running into the same problem and do not want to have to make redundant calls to the database just to get the comments count if we already have the blog post object: dataItem.Comments.Count always shows zero.
  8. Richard
    Richard avatar
    103 posts
    Registered:
    04 Apr 2013
    30 Jul 2014 in reply to Basem
    Link to this post

    This does not appear to work properly in sf6.3.5000. I attempt to use blogPost.Comments.Count and it's always 0. 

  9. Richard
    Richard avatar
    103 posts
    Registered:
    04 Apr 2013
    30 Jul 2014 in reply to Basem
    Link to this post

     

9 posts, 1 answered