Try our conversational search powered by Generative AI!

Top Rated entries query

Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.