Sorting on Related fields

Posts   
 
    
Posts: 14
Joined: 07-Dec-2006
# Posted on: 01-Mar-2007 23:08:06   

I would like to use the ISortExpression to sort a Collection on a related table. Is this possible? When I try to do this, I get a " The multi-part identifier can not be bound".

Backgroud: The "EnterpriseUser" class is a global user we use for all applications. "TmsUser" is a user of one of our sub-systems, and is related to "EnterpriseUser" via UserID's (EnterpriseUser.UserId = TmsUser.UserId). I have a custom relationship setup that links these two together in LLBLGen. Since the EnterpriseUser contains last name, and TmsUser only contains the UserId, I want to sort a collection of TmsUsers by EnterpriseUser.LastName. The below code does not work, but maybe you could provide me with a workaround to acheive this goal...Any help is greatly appreciated.

Below is my code.


List<TMSUser> lstTMSUsers = new List<TMSUser>();
_tmsUserCollection = new TmsUsersCollection();

// filter statement
IPredicateExpression filter = new PredicateExpression();

filter.Add(new FieldCompareValuePredicate(
    TmsUsersFields.IsTimeApprover, ComparisonOperator.Equal, true));

if (enumActiveStatus != TmsActiveStatus.All)
{
        bool activeStatus = Convert.ToBoolean(enumActiveStatus);
        filter.AddWithAnd(new FieldCompareValuePredicate(
                 TmsUsersFields.IsActive, ComparisonOperator.Equal, activeStatus));
}

// sort statement - here is where it bombs
[b]ISortExpression sortBy = new SortExpression([u]EnterpriseUserFields.LastName [/u]| SortOperator.Ascending);[/b]

_tmsUserCollection.GetMulti(filter, 0, sortBy);
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Mar-2007 02:09:21   

You would use a PrefethPath for the related entity, and specify an sortClause for that entity at PrefetchPath constructor. Check this Help Section: Using generated code - SelfServicing - Prefetch paths - Advance Prefetch paths

David Elizondo | LLBLGen Support Team
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 02-Mar-2007 02:13:31   

You need to include the relationship between EnterpriseUser and TmsUser with the GetMulti as the fourth parameter and it should work.

May be something like this;

IRelationCollection relations = new RelationCollection();
relations.Add(TmsUserEntity.Relations.EnterpriseUserUsingUserId);
_tmsUserCollection.GetMulti(filter, 0, sortBy, relations);

Posts: 14
Joined: 07-Dec-2006
# Posted on: 02-Mar-2007 14:24:19   

I added the relation and it worked fine! Thank you both for your replies...I will keep the prefetch in my back pocket for future reference! -cory