I'm using LLBLGen Pro 2.0.0.0 Final with adapter and .NET 2.0/c# connecting to a SQL Server 2005 dB.
Can anyone tell me how I might create a SortExpression that would generate a SQL expression that looks like the one below?
select activity.*
from activity
left outer join account on activity.regardingaccountid = account.recid
left outer join contact on activity.regardingcontactid = contact.recid
order by
case
when activity.regardingaccountid is not null then account.name
when activity.regardingcontactid is not null then contact.name
else ''
end desc
For further background, in my database an Activity can be linked to an Account or a Contact or neither. I have an Activity, Account and Contact entity and for the Activity entity I have create a "Fields on related fields" for the Name of the Account and Contact entities. I have then extended the LLBL Gen generated ActivityEntity class and included a property that looks like this:
public virtual System.String RegardingName
{
get
{
if (this.RegardingAccountId != null)
{
return this.RegardingAccountName;
}
else if (this.RegardingContactId != null)
{
return this.RegardingContactName;
}
else
{
return string.Empty;
}
}
}
Once I have retrieved a collection of Activity entities I bind this property to the column of a listview and within the listview the user can choose to sort by the RegardingName or a number of other bound Activity properties.
Previously the sorting was performed internally within my listview control but I am now going to implement data paging so I need to perform the sorting on the server.
As ever any help would be greatly appreciated.
Chris