EF LINQ queries The pit of data over a time period

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.