I am getting records from a database using Linq to Entities as follows:
context.Orders.OrderBy(x => x.Schedule)
In this case I am ordering by DateTime Schedule ...
I would like to still order by DateTime Schedule but first I would like to show the ones which date is after today ad after it the ones which day are in the past.
How can I do this?
Right, it sounds like you want something like:
DateTime startOfDay = DateTime.UtcNow.Date;
var results = context.Orders
.OrderBy(x => x.Schedule < startOfDay)
.ThenBy(x => x.Schedule);
That's assuming that EF still orders "false" before "true" - it would work in LINQ to Objects, certainly, but I don't know for sure in EF. Worth a try.
See more on this question at Stackoverflow