我有这个表达式:
troubletickets = db.ServiceTickets.Include(t => t.Company).Include(t => t.UserProfile);
troubletickets.OrderByDescending(t => t.UserProfile != null ? t.UserProfile.FirstName : "ZZZ");
我必须检查UserProfile是否为空,因为如果不检查就会出错。问题是,有时UserProfiles.FirstName可能为空。当它为空时,在按升序和降序排序时,这些值将放置在列表的顶部。例如:
// Null, Null, Andy, Bill, Chris
// Null, Null, Chris, Bill, Andy
如何修改这个表达式,使得当我按降序排序时,返回类似以下的结果:
// Chris, Bill, Andy, Null, Null