CurrentUtcDateTime does not exist - Entity Framework and MySql

后端 未结 3 1686
悲&欢浪女
悲&欢浪女 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);
    

提交回复
热议问题