Fetch with condition "Where String Contains"

Posts   
 
    
Posts: 30
Joined: 08-Apr-2008
# Posted on: 24-Apr-2008 14:13:54   

Hi!

I've got 3 tables in the scenario that I'm working with - User, Role and UserRole (to maintain the many-to-many relationship between User and Role).

I've got the join between all 3 tables using RelationPredicateBucket.Relations but can't seem to figure out how to add the "Where username contains 'xyz'" condition.

Here's my code snippet:


EntityCollection<UsersEntity> usersColl = new EntityCollection<UsersEntity>();

RelationPredicateBucket rpb = new RelationPredicateBucket();
rpb.Relations.Add(UserRolesEntity.Relations.UsersEntityUsingUserId, JoinHint.Inner);
rpb.Relations.Add(RolesEntity.Relations.UserRolesEntityUsingRoleId, JoinHint.Inner);
rpb.PredicateExpression.AddWithAnd(RolesFields.Name == roleName);
//TODO add expression UsersFields.EmailId.Contains(usernameToMatch)
//rpb.PredicateExpression.AddWithAnd(UsersFields.EmailId.           

DataAccessAdapter daa = new DataAccessAdapter();
daa.FetchEntityCollection(rolesColl, rpb);

Any help appreciated.

Regards, Nitin

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Apr-2008 15:50:14   

Try the following:

EntityCollection<UsersEntity> usersColl = new EntityCollection<UsersEntity>();

RelationPredicateBucket rpb = new RelationPredicateBucket();
rpb.Relations.Add(UserEntity.Relations.UserRolesEntity...);
rpb.Relations.Add(UserRolesEntity.Relations.RolesEntity...);

rpb.PredicateExpression.AddWithAnd(RolesFields.Name == roleName);
rpb.PredicateExpression.AddWithAnd(UsersFields.EmailId % "%xyz%");          

DataAccessAdapter daa = new DataAccessAdapter();
daa.FetchEntityCollection(rolesColl, rpb);

Hint: define the relations starting from the entity you are fetching (check the above code).