Wildcard select via linking table

Posts   
 
    
Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 15-May-2007 04:47:13   

I'm using the SelfServicing model with LLBLGen Pro v2., SQL Server 2000 database.

I have a Users table and a Roles table which are joined by a linking table (ie m:n via UsersInRoles).

I need to retrieve a collection of Users matching a wildcard search (FieldLikePredicate?) for a particular role.

I can retrieve the list of users ok, using role.GetMultiUsersCollectionViaUsersInRoles(true), but there's no overload to accept a filter on the Usernames. I can't find any way to filter on the newly retrieved list of users, either. Somehow I think I'm barking up the wrong tree.

Can you throw some light on the subject? Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-May-2007 08:22:58   

Hi Meteor,

The role.GetMultiUsersCollectionViaUsersInRoles(true) already contain a filter that ensure all the users matching the role are fetched without fetch the _UsersInRoles _collection.

I think the best way in this case is you to use a difrerent collection and filter by _roleId _(UsersInRoles table) and by _UserName _(like predicate).

Other thing you can do is filter in memory with Collection.FindMatches(filter)...

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 15-May-2007 10:45:11   

Meteor wrote:

I'm using the SelfServicing model with LLBLGen Pro v2., SQL Server 2000 database.

I have a Users table and a Roles table which are joined by a linking table (ie m:n via UsersInRoles).

I need to retrieve a collection of Users matching a wildcard search (FieldLikePredicate?) for a particular role.

I can retrieve the list of users ok, using role.GetMultiUsersCollectionViaUsersInRoles(true), but there's no overload to accept a filter on the Usernames. I can't find any way to filter on the newly retrieved list of users, either. Somehow I think I'm barking up the wrong tree.

Can you throw some light on the subject? Thanks.

To elaborate on what David said: you need a GetMulti call on the UserCollection. You then pass a relation collection with 2 relation: User - UsersInRole

UsersInRole already contains RoleID, so you don't have to specify UsersInRole - Role.

You then also specify a predicateexpression with the following filter: PredicateExpression filter = new PredicateExpression(); filter.Add(UserFields.UserName % myPattern); filter.AddWithAnd(UsersInRoleFields.RoleID==roleID);

The getmulti call on the usercollection will then fetch all users which match that filter and use the relation in the relationcollection.

Frans Bouma | Lead developer LLBLGen Pro
Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 15-May-2007 12:17:38   

You then pass a relation collection with 2 relation: User - UsersInRole

Thanks for the response. I'll give that a try. I'm a bit unclear on how the relations work, but I'll look it up in Help confused .