I have a repository method which retrieve a list of items, for example:
StaffID: 250026965
Name: Abbasov Islam
FreeTextName: NULL
StaffID: NULL
Name: NULL
FreeTextName: Antonio Puccio
StaffID: 358
Name: Prosinecki Robert
FreeTextName: NULL
I have to sort this list in this manner:
First the items with StaffID > 0
by Name, then the items with StaffID == NULL
by FreeTextName
.
In the example case:
StaffID: 250026965
Name: Abbasov Islam
FreeTextName: NULL
StaffID: 358
Name: Prosinecki Robert
FreeTextName: NULL
StaffID: NULL
Name: NULL
FreeTextName: Antonio Puccio
At the moment I am doing:
var resList = conn.Query<TeamSheetStaffPoco>("[dbo].[TList]", p, commandType: CommandType.StoredProcedure).AsList();
var result = resList.Where(x => x.StaffID> 0).OrderBy(y => y.Name).ToList();
result.AddRange(resList.Where(x => x.StaffID== null).OrderBy(y => y.FreeTextName).ToList());
It works, but I am not sure if exist a more concise and elegant mode to to do the same thing.