How to retrieve IUser by an extension method value

Vote:
 

I have defined an extension method on IUser to check whther the user is valid according to some criteria.

public static bool IsValidMember(this IUser user)
{// validation logic}

Then I have a UserQuery and I need to filter the result based on this extension method. I tried something like this;

UserQuery membersQuery = new UserQuery();
BooleanCriterion criteria = new BooleanCriterion{Value = true};
membersQuery["IsValidMember"] = criteria;
UserCollection members = QueryHandler.Instance.GetQueryResult(membersQuery);

This gives an System.ArgumentException that 'There is no attribute with the name IsValidMember for the type EPiServer.Common.Security.IUser'.

How can I possibly filter the users based on an extension method?  

#187557
Edited, Jan 26, 2018 6:49
Vote:
 

I don't think you can.

I think the query will be converted to sql and sent to the database to enable filtering be done prior to loading the users from the database.

Your extension method won't be available in the database, all you can do is retrieve all users from the database and afterwards filter them according to your extension method.

I hope i don't have to point out the inherited performance issues with such a solution. yell

#187599
Jan 29, 2018 16:04
Vote:
 

Yes, filtering after retrieving Users, currupts the pagination and total number. Unfortunately that's not a good solution in my case. :( 

What do you recommend for such a scenario?

#187618
Jan 30, 2018 5:19
Vote:
 

I can't say for certain without knowing what it is you do in your extension method, but most likely you would have to store it's result on the IUser with SetAttributeValue before hand. It would require you to keep it updated as well whenever something the method relies on changes.

That would enable you to run your query and filter in the database before loading the users.

#187638
Jan 30, 2018 15:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.