Member Join Table with Ordering - help with using generated code

Posts   
 
    
llezz
User
Posts: 3
Joined: 03-Jan-2008
# Posted on: 20-Mar-2008 15:32:11   

Version: LLBLGen Pro 2.5 Build Number: Dec 5th 2007 Runtime Library Version: 2.5.08.0122 Template Group: SelfServicing DotNet: 2.0 Database Type: SQL Server 2000

Hi I'm having a bit of trouble designing the necessary llblgen code to perform the following SQL request:

SELECT u.* FROM User u JOIN UserGroupMember m ON m.UserId = a.UserId JOIN Group g ON g.GroupId = m.GroupId WHERE u.IsDeleted = 0 AND g.IsDeleted = 0 ORDER BY m.Order

So you see I am requesting a collection of Users, filtered by the deleted properties of itself and the related table. I am also requesting the order to be according to the member table Order column.

So far I have come up with the following LLBLGen code:

UserCollection users = new UserCollection(); IPredicateExpression filter = new PredicateExpression(); IRelationCollection relations = new RelationCollection();

filter.Add(UserFields.Deleted == 0); filter.Add(GroupFields.Deleted == 0);

// link in to the query the member table, and the group table relations.Add(UserEntity.Relations.UserGroupMemberEntityUsingUserId); relations.Add(UserGroupMemberEntity.Relations.GroupEntityUsingGroupId);

sort.Add(new SortClause(UserGroupMember.Order, SortOperator.Ascending));

users.GetMulti(filter, long.MaxValue, sort, relations);

This seems to work, but I wonder if you can just take a look to confirm if this is the best way to do it?

Many thanks for any comments

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Mar-2008 10:16:13   

It is the right way of doing it simple_smile

Just a small comment, if you want to fetch all rows, pass 0 instead of long.MaxValue.