我正在使用 Linq to Entities 从数据库获取记录,如下所示:
context.Orders.OrderBy(x => x.Schedule)
在这种情况下,我按 DateTime Schedule ...
我仍然想按 DateTime Schedule 订购,但首先我想显示今天之后的日期,然后显示过去的日期。
我该怎么做?
最佳答案
是的,听起来你想要这样的东西:
DateTime startOfDay = DateTime.UtcNow.Date;
var results = context.Orders
.OrderBy(x => x.Schedule < startOfDay)
.ThenBy(x => x.Schedule);
假设 EF 仍然在“true”之前命令“false”——它当然可以在 LINQ to Objects 中工作,但我不确定在 EF 中。值得一试。
关于c# - 按日期排列的列表,将 future 与过去日期分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25096136/