CurrentUtcDateTime does not exist - Entity Framework and MySql

后端 未结 3 1661
悲&欢浪女
悲&欢浪女 2021-01-14 17:09

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

相关标签:
3条回答
  • 2021-01-14 17:20

    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);
    
    0 讨论(0)
  • 2021-01-14 17:30

    Based on Bohemian's suggestion, I fixed this issue with a "bypass" function.

    CREATE FUNCTION `your_schema`.`CurrentUtcDateTime` ()
    RETURNS TIMESTAMP DETERMINISTIC
    RETURN UTC_TIMESTAMP();
    
    0 讨论(0)
  • 2021-01-14 17:32

    Use UTC_TIMESTAMP()

    0 讨论(0)
提交回复
热议问题