var now = DateTime.Now;
var list =db. Jinbi_typelimit.where (x = x.isavailable && X.jinbitype = = Jinbitype && x.startdatetime <= now & ;& now <= x.enddatetime); // . ToList (); var list1 =db. Jinbi_typelimit.where (x = x.isavailable && X.jinbitype = = Jinbitype && x.startdatetime <= DateTime.Now && DateTime.Now <= x.enddatetime); // . ToList ();
Results of execution:
List: two data
list1:0 Bar Data
Cause Analysis:
List
The statement that the final database executes, the time comparison section is translated into
X.startdatetime <= ' 2015-12-07 ' && ' 2015-12-07 ' <= x.enddatetime
List1:
The statement that the final database executes, the time comparison section is translated into
X.startdatetime <= (Sysdatetime ()) && (Sysdatetime ()) <= X.enddatetime
There is nothing wrong with the statement itself, but if the program and database are not on a single server (which is now the case in most cases), if the time is different for the Web server and the database server, this is the case. (It is estimated that you have thought of it now)
For list, time is the variable passed in, and that is the Web server's system time
For List1,sysdatetime () is the database server's system time
If the system time set by the two servers is different, you know. It must be different.
Today debug code found problems, left as a souvenir.
I don't know which two forced the server to change the time.
EF LINQ queries The pit of data over a time period