MySql中的EntityFunctions支持 [英] EntityFunctions support in MySql
问题描述
在与MySQL一起使用EntityFunctions.DiffMinutes()时出现错误.下面是我的代码
I am getting error while using EntityFunctions.DiffMinutes() with MySQL. Below is my code
返回db.DiscoveredDevices.Where(m => EntityFunctions.DiffMinutes((DateTime)m.LastPollTime,DateTime.Now)< = pollTime&& m.Status == true).ToList();
return db.DiscoveredDevices.Where(m => EntityFunctions.DiffMinutes((DateTime)m.LastPollTime, DateTime.Now) <= pollTime && m.Status == true).ToList();
此函数接受两个dateTime对象,并以分钟为单位返回差值.在MSSQL中可以正常工作,但在与MySQl一起使用时会显示错误"DiffMinutes不存在".
this function takes two dateTime objects and returns difference in minutes. this works fine in MSSQL but shows error "DiffMinutes does not exist" when using with MySQl.
如果我使用自定义方法或任何内置的DateTime方法,则会引发异常"LINQ to Entities无法识别此方法"
If I use my custom or any built in DateTime method than it throws exception "LINQ to Entities does not recognize this method "
如果有人能帮助我,我将不胜感激
I will be grateful if somebody helps me in this
致谢 Umair Zaman
regards Umair Zaman
推荐答案
DiffMinutes函数在MySQL中不存在,只需创建即可使用:
The DiffMinutes function doesn't exist in MySQL, just create it and will work:
CREATE FUNCTION `DiffMinutes`(timeValue1 datetime, timevalue2 datetime) RETURNS int(11)
DETERMINISTIC
BEGIN
RETURN TIMESTAMPDIFF(MINUTE, timeValue1, timevalue2);
END
这篇关于MySql中的EntityFunctions支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!