Alternative to EntityFunctions.AddSeconds for MySQL

蹲街弑〆低调 提交于 2019-12-11 11:07:16

问题


I need to execute an EF LINQ query that adds some seconds to a datetime against MySQL using the standard Oracle supplied dot net connector. Unfortunately it does not support the EntityFunctions.AddSeconds method. Is there an alternative approach?

var result = (from rec in db.Records where EntityFunctions.AddSeconds(rec.SomeDate, rec.SomeSeconds) select rec).FirstOrDefault();

回答1:


DELIMITER $$
drop function IF EXISTS AddSeconds$$
create function AddSeconds(theDate datetime, seconds int)
RETURNS datetime
DETERMINISTIC
begin
 return DATE_ADD(theDate, INTERVAL seconds SECOND);
end$$


来源:https://stackoverflow.com/questions/12951714/alternative-to-entityfunctions-addseconds-for-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!