Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi,
The GetQueryResult method contains an overload that accepts paging:
ClubHandler.Instance.GetQueryResult(query, pagerIndex, pageSize, out totalItems);
When it comes to the sorting, from what I can see in the GetOrderByQuery() method in EPiServer.Common.Queries.QueryBase you can only sort on a property that exists in your query object. So in your case, you can only sort on the properties of the MembershipQuery class:
// In the GetOrderByQuery() method
foreach (CriterionSortOrder order in this.OrderBy)
{
CriterionBase criterion = (CriterionBase) order.Criterion;
string name = criterion.ParentQuery.CriteriaReverse[criterion];
if (base.GetType().GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) == null)
{
throw new ApplicationException(string.Format("The criterion '{0}' does not represent a database column, and cannot be sorted on.", name, criterion.GetType().ToString()));
}
if (order != this.OrderBy[0])
{
builder.Append(", ");
}
builder.Append(order.ToString());
}
If you take a look at the code above, you see that base.GetType().GetProperty(...) returns null in your case because MembershipQuery does not contain a GivenName property.
I've tried to figure out if there's any way to get around this, but sadly I couldn't find any other way than the LINQ solution you also came up with.
I hope this helped you understand the error message, sorry I couldn't find a solution!
Karoline
Hi BoyanNikolov,
I am now getting the same issue with you.
If you have got through this, can you specify your way to achieve it?
And please can you tell me how can I take just users only.
Thanks!
Hi,
I'm using this 2 lines of code to get Club approved members sorted by users names:
This is working fine, but now I need to get only members with specific attributes.
I tried this code:
MembershipQuery query = new MembershipQuery();
query.Club = new ClubCriterion();
query.Club.ID = new EPiServer.Common.Queries.IntegerCriterion() { Value = club.ID, Operator = EPiServer.Common.Queries.ComparisonOperator.Equals };
query.MembershipType = new MembershipTypeCriterion();
query.MembershipType.Value = MembershipType.Member;
query.User = new UserCriterion();
query.User["AttributeName"] = new StringCriterion() { Value = "AttributeValue" };
MembershipCollection memberships = ClubHandler.Instance.GetQueryResult(query);
but I can't make it sorted and the pagging is lost. Using :
thrown an error - "The criterion 'GivenName' does not represent a database column, and cannot be sorted on"
Is there any way to overcome this or using LINQ is the only solution. Something like this:
Thank you in advance.