I am trying to order my query by null values on one column and then by another column as seen in this post.
_ctx.Leads.Include(a => a.LeadAttachments)
.Where(s => s.Name.ToLower().StartsWith(filter))
.OrderBy(a=>a.AcceptedOn.HasValue)
.ThenByDescending(a => a.AssignedOn)
.Skip(offSet)
.Take(12)
.ToList()
I get this error when adding .OrderBy(a=>a.AcceptedOn.HasValue)
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.Core.dll but was not handled in user code
Additional information: Incorrect syntax near the keyword 'IS'.
Invalid usage of the option NEXT in the FETCH statement.
Both my order by columns are of typeNullable<DateTime>
.
What is wrong with this query? Is there a better way of sorting?
UPDATE:
Thanks to @vamsi answer, I am not having this error. Now I need this to sort like the following:
All records that have a null
value for AcceptedOn
should be first
All records that have a value for both dates should be sorted by AssignedOn
not AcceptedOn
Is this possible?