Order by descending by row field in query

Viewed 195

I want to write a EF query which does order by ascending or descending based on condition. Following is the my pseudo code:

      var result= q.OrderByDescending(x => x.StatusId == 3)
                         if( x.StatusId == 3) 
                              then order by x.ReserveDate
                         if( x.StatusId != 3 ) 
                              then order by descending x.LastUpdateDate

How can i do this?

Update

This is not same as q = condition ? q.OrderBy(..) : q.OrderByDescending(..) as marked in referenced duplicate question, sorting order differs based on value within the row instead of a flag outside query.

2 Answers
Related