Hello I am trying to get a query to order by dates but if there is a due_date to use that if there isn't a due_date it needs to use sample_date. This is what i tried but it isnt correct.
is there a way to use a conditional in a orderby or a thenby or no?
Nulls appear in ascending sorting as first records. We can avoid this by coalesce operator:
session.Query<ActiveTestListResult>()
.OrderByDescending(x => x.lab_int)
.ThenBy(x => x.due_date ?? x.sample_date)
.ThenBy(x => x.sample_id)
.ThenBy(x => x.batch_id)