also I can't seem to filter by Author name
query.Author.Name = new StringCriterion();
query.Author.Name.Value = "admin";
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
Thanks, I used your exaample but i get "The criterion 'NumRatings' does not represent a database column, and cannot be sorted on."
Hi Saar,
Apparently there is a bug in the query system. I have posted this bug to the Community team.
Best regards,
Tom
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