Top Rated entries query | Episerver Developer Community

Top Rated entries query

 

Hi, I am trying to get the top rated entries (IsPlan is a custom attribute). The code below gives me "Object reference not set to an instance of an object."

int totalItems;
EntryQuery query = new EntryQuery();
BooleanCriterion IsPlan = new BooleanCriterion();
IsPlan.Value = true;
query["IsPlan"] = IsPlan;
query.Rating.NumRatings = new IntegerCriterion();
query.OrderBy.Add(new CriterionSortOrder(query.Rating.NumRatings, SortingDirection.Descending));
EntryCollection Entries = QueryHandler.GetQueryResult(query, StartPageNumber, ucPopularPlans.PageSize, out totalItems);
ucPopularPlans.PageNumber = StartPageNumber;
ucPopularPlans.PageSize = ucPopularPlans.PageSize;
ucPopularPlans.TotalCount = totalItems;
ucPopularPlans.Entries = Entries;
ucPopularPlans.DataBind();

 

Thanks

#30745 Jun 18, 2009 4:43
  •  

    also I can't seem to filter by Author name

    query.Author.Name = new StringCriterion();
    query.Author.Name.Value = "admin"; 

    #30746 Jun 18, 2009 5:18
  • Member since: 2007
     

    Hi Saar,

    The problem is that you have not initilized the Rating property, you have to add this row:

    query.Rating = new RatableItemCriterion(); 

    Before you try to init NumRatings. The same goes if you want to filter on Author, then you must first init the Auhtor property before init Name of Author.

    The query will look like this:

    int totalItems;
    EntryQuery query = new EntryQuery();
    BooleanCriterion IsPlan = new BooleanCriterion();
    IsPlan.Value = true;
    query["IsPlan"] = IsPlan;
    query.Rating = new RatableItemCriterion();
    query.Rating.NumRatings = new IntegerCriterion();
    query.OrderBy.Add(new CriterionSortOrder(query.Rating.NumRatings, SortingDirection.Descending));
    EntryCollection Entries = QueryHandler.GetQueryResult<Entry, EntryCollection>(query, StartPageNumber, ucPopularPlans.PageSize, out totalItems);

    Best regards,
    Tom

    #30750 Edited, Jun 18, 2009 10:36
  •  

    Thanks, I used your exaample but i get "The criterion 'NumRatings' does not represent a database column, and cannot be sorted on."

     

    #30769 Jun 18, 2009 16:11
  • Member since: 2007
     

    Hi Saar,

    Apparently there is a bug in the query system. I have posted this bug to the Community team.

    Best regards,
    Tom

    #30786 Jun 22, 2009 10:25
  • Member since: 2008
     

    Any news on this bug? I get the same error.

    // Regards, Torbjörn

    #46983 Edited, Jan 13, 2011 12:02
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
Please login to post a reply