I have a query that needs to be ordered as follows:
var list = new List<MonthClosureViewModel>(); var orderedList = list .OrderByDescending(x => x.Project) .ThenByDescending(x => x.ChargeLine) .ThenByDescending(x => x.DomesticSite)
But if any object is null (completely by design), this request fails. How can I put null values at the end or skip the order if the object is null?
ADDED: as @ LasseV.Karlsen mentioned that I may have another problem. I actually got an ArgumentNullException , but the reason is not that some object was null (I saw it in the debugger and falsely thought that this was my problem). The real reason was that @ RaphaëlAlthaus mentioned that I did not implement IComparable<> in ANY of my classes in MonthClosureViewModel ...
After I have done this, everything will start working as intended, even if the object is null
Szer source share