I'm trying to sort the UserEntity objects in the UserCollection by fields that are NOT null. Lets say my UserEntity has the following fields: FirstName, AlternateFirstName, LastName, AlternateLastName. The alternate first and last names can be null, but the first and last names will always contain a value.
I need to programmatically populate a TreeView with TreeNodes created from these UserEntity objects, and have them be sorted using the logical "Last name, First name" order. The last name will be the value LastNameAlternate field if it is NOT null, otherwise the LastName field is used. Same for the first name.
I tried to use a SortExpression in the GetMulti() method when retrieving from the database, but somehow it doesn't sort correctly. My code for the SortExpression is:
SortExpression sorter = new SortExpression();
sorter.Add(UserFields.AlternateLastName | SortOperator.Ascending);
sorter.Add(UserFields.LastName | SortOperator.Ascending);
sorter.Add(UserFields.AlternateFirstName | SortOperator.Ascending);
sorter.Add(UserFields.FirstName | SortOperator.Ascending);
So now I'm looking for a way to sort the collection after retrieval from the database. Looks like I have 3 ways to try to implement this customized sorting:
1) Find a way to sort the objects within the collection in memory.
2) Create a SortableUserEntity class that inherits from UserEntity and implement the IComparable interface. I can then use an ArrayList to store and sort these objects.
3) Create a SortableTreeNode class that inherits from TreeNode and implement the IComparable interface. I can then use an ArrayList to store and sort these nodes.
Which is the best way? Please give me some suggestions for how as well. Thanks.