When I use
datacontext.News
.Where(p => p.status == true)
.Where(p => p.date <= DateTime.Now)
.ToList();
the system will return no results;
When I use
datacontext.News
.Where(p => p.status == true)
.ToList()
.Where(p => p.date <= DateTime.Now)
.ToList();
system will return expected results. Can anyone tell me what’s up?
Thanks in advance !
I best guess is that the time settings on your database server differ from that on your developer machine (or the machine you run .NET on).
The difference between the two snippets is that in the second snippet the condition
p.date <= DateTime.Nowis executed locally, and not on the database server.If you want to use local time, you can do this: