UPDATE . My original question was invalid because I did not read MySql logs correctly. I'm sorry. See below, updated.
I am using the LINQ query:
var homework = ctx.Threads.Where(t => t.ClassName == "10L" && t.EndDate != null && t.StartDate <= DateTime.Now && t.EndDate > DateTime.Now) .OrderByDescending(o => o.EndDate) .FirstOrDefault();
This creates SQL (MySQL 5.5.14):
SELECT `Project1`.`id`, `Project1`.`title`, `Project1`.`startdate`, `Project1`.`enddate`, `Project1`.`class`, `Project1`.`body`, `Project1`.`threadtype` FROM (SELECT `Extent1`.`id`, `Extent1`.`title`, `Extent1`.`startdate`, `Extent1`.`enddate`, `Extent1`.`class`, `Extent1`.`body`, `Extent1`.`threadtype` FROM `threads` AS `Extent1` WHERE (((`Extent1`.`class` = '10L') AND (`Extent1`.`enddate` IS NOT NULL)) AND (`Extent1`.`startdate` <= (NOW()))) AND (`Extent1`.`enddate` > (NOW()))) AS `Project1` ORDER BY `Project1`.`enddate` DESC LIMIT 1
How does LINQ to EF know how to use the NOW()
function? Of course, I just pass it a regular DateTime
structure by value?
If I use var now = DateTime.Now;
and then use the now
variable in the LINQ query, the date is passed as a literal. What's happening?
James source share