我降序有這樣的表達:LINQ排序空值在底部
troubletickets = db.ServiceTickets.Include(t => t.Company).Include(t => t.UserProfile);
troubletickets.OrderByDescending(t => t.UserProfile != null ? t.UserProfile.FirstName : "ZZZ");
我要檢查,如果用戶配置爲null,因爲如果我不這麼做,我會得到一個錯誤。問題是,有時UserProfiles.FirstName可能爲空。當它爲空時,當我按升序和降序進行排序時,這些值被放置在列表頂部。例如。
// Null, Null, Andy, Bill, Chris
// Null, Null, Chris, Bill, Andy
我怎樣才能改變這種表達,這樣,當我通過降序排列返回這樣的事情,而不是:
// Chris, Bill, Andy, Null, Null
這個建議工作完美。謝謝! – mdk09 2014-10-03 21:00:46