Reputation: 117
i have custom a collection LoanOptionsProgramVersionList
which has bolean property Configured
,string Description
and Code
.While insert and delete from the collection i want sort the collection in the below order. So one record inserted to database configured become yes. When deleted Configured
become "No". So it Notify property.
i have tried the below code After insert.
IOrderedEnumerable<ProgramVersionRecord> orderedList =
LoanOptionsProgramVersionList
.OrderByDescending(p => p.ProgramVersionConfigured == true);
Also below code for deletion
IOrderedEnumerable<ProgramVersionRecord> orderedList =
LoanOptionsProgramVersionList.OrderBy(p => p.Description);
Any help will be appreciated.
Upvotes: 0
Views: 180
Reputation: 236188
When ordering by ProgramVersionConfigured
property use this property instead of result of comparison with boolean. Also use ThenBy
to add another sorting:
LoanOptionsProgramVersionList.OrderByDescending(p => p.ProgramVersionConfigured)
.ThenBy(p => p.Description)
.ThenBy(p => p.Code)
Upvotes: 1
Reputation: 460038
Use ThenBy
IOrderedEnumerable<ProgramVersionRecord> orderedList = LoanOptionsProgramVersionList
.OrderByDescending(p => p.ProgramVersionConfigured) // configured has priority
.ThenBy(p => p.Description)
.ThenBy(p => p.Code);
Upvotes: 4