I am having a problem with canonical functions in Entity Framework 4.1 and MySql Connector/Net 6.4.3. According to Microsoft cannonical functions are understood and translat
I encountered this exact same problem and lost almost two days trying to figure it out. It appears to be a bug in the EntityFramework mappings for MySql.
The solution is to move the DateTime.UtcNow calculation outside of the scoped lambda and plug in the actual value.
var utcNow = DateTime.UtcNow;
query = query.Where(p => p.Published);
query = query.Where(p => !p.StartDate.HasValue || p.StartDate <= utcNow);
query = query.Where(p => !p.EndDate.HasValue || p.EndDate >= utcNow);
Based on Bohemian's suggestion, I fixed this issue with a "bypass" function.
CREATE FUNCTION `your_schema`.`CurrentUtcDateTime` ()
RETURNS TIMESTAMP DETERMINISTIC
RETURN UTC_TIMESTAMP();
Use UTC_TIMESTAMP()