我希望能够按d.DateUpdated
排序,但只有当它不是DateTime.MinValue时才能排序。如果它是DateTime.MinValue,那么我需要它能够按d.DateCreated
排序。有没有办法在下面的代码行中执行此操作?
return database.Table<Announcement>()
.Where(i => i.GroupId == groupId)
.OrderByDescending(d => d.DateUpdated)
.ToListAsync();
答案 0 :(得分:3)
您也可以使用ThenBy
方法
return database.Table<Announcement>()
.Where(i => i.GroupId == groupId)
.OrderByDescending(d => d.DateUpdated)
.ThenByDescending(d => d.DateCreated)
.ToListAsync();
答案 1 :(得分:0)
那样的东西?
return database.Table<Announcement>()
.Where(i => i.GroupId == groupId)
.OrderByDescending(d => d.DateUpdated == null ? d.DateCreated : d.DateUpdated)
.ToListAsync();