Get latest comments from a category

Joel Yourstone
Member since: 2016

Hi all!

We're in the process of building an epi cms block that does what the title dictates, it gets the latest X comments (optional from comments on a product from a specific category) and displays them in a list.

We're not really sure how to manage this, however. First part is easy, getting the latest comments is just querying all Comments with the composite class Y we're using and sorting by date. The tricky part comes when we want to do it per category. All comments with composite class Y are tightly coupled with variants in episerver, however which categories a variant is included in does not exist in epi social, yet. It would make sense to create a

public List Categories { get; set; }

on the composite Y, since a varaint can be in several categories. Now, since we want to fetch all comments where


but I don't see any way of implementing this logic with the current commentrepository-API.

How can I solve this? It feels like a pretty common use case for comments, to show latest comments/ratings/reviews on a category page.

#174703 Feb 02, 2017 14:32
  • Chris Banner
    Member since: 2015

    Hi Joel,

    The platform doesn't officially offer a "Contains" expression at this time (the feature is currently in the product backlog) but there is an undocumented behavior that may suffice for you until such a feature is implemented.

    It so happens that the EqualToExpression, when used against a collection of the supported value types, will behave like a "contains" operation. So, if you apply an extension filter to your criteria (CompositeCriteria<TFilter,TExtension>.ExtensionFilter), which leverages the EqualToExpression against the Categories field, the results will actually be limited to those that contain the desired category.

    For example:

    var criteria = new CompositeCriteria<CommentFilter, TestData>
        ExtensionFilter = FilterExpressionBuilder<TestData>.Field(td => td.Categories).EqualTo(categoryNameDefinedInBlock)                    

    While it's not an officially supported behavior, we have no plans to remove the behavior in the foreseeable future. I think that will acheive what you're looking to do in the near term.

    #174737 Feb 02, 2017 21:06
  • Joel Yourstone
    Member since: 2016

    Hi Chris,

    Well that was a hidden suprise! Haven't tried it out yet, but if what you say is true you should promote this in your documentation! :) Will return with feedback if I get any issues with it.


    Joel Yourstone

    #174849 Feb 07, 2017 6:39
  • Chris Banner
    Member since: 2015

    Yes -- it's more of a convenient quirk at this point. It will certainly be documented when we introduce formal support in the form of a "contains" expression in the near future.

    #174919 Feb 07, 2017 20:51
  • Joel Yourstone
    Member since: 2016

    I think AI is taking over...embarassed Moderators, do your thing!

    #188153 Feb 13, 2018 11:14

    Hi Joel, we have done our thing. ;-)

    #188154 Feb 13, 2018 11:25