BlogPost.Comments.Count is always 0

Posted by Community Admin on 04-Aug-2018 22:36

BlogPost.Comments.Count is always 0

All Replies

Posted by Community Admin on 29-Feb-2012 00:00

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;

Posted by Community Admin on 01-Mar-2012 00:00

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

Posted by Community Admin on 02-Mar-2012 00:00

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

Posted by Community Admin on 02-Mar-2012 00:00

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

Posted by Community Admin on 02-Mar-2012 00:00

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

Posted by Community Admin on 07-Mar-2012 00:00

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

Posted by Community Admin on 14-Apr-2012 00:00

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.

Posted by Community Admin on 30-Jul-2014 00:00

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

Posted by Community Admin on 30-Jul-2014 00:00

 

This thread is closed