I want to add Timespan to DateTime in EntityFramework with MySql Database.
i have tried using DbFunctions.AddMinutes(someminutes)
and EntityFunctions.AddMinutes(someminutes)
but when i execute i get exception something like
FUNCTION projectName.AddMinutes does not exist
i have googled but cannot find how to execute canonical function. though there is a list of function but again i don't know which class they belong https://msdn.microsoft.com/en-us/library/bb738563.aspx
I am using
My Linq Query is as below
IQueryable<OrderViewModel> orders = _dbContext.Orders
.OrderByDescending(x => x.ID)
.Select(x => new OrderViewModel
{ ID = x.ID,
AddedOn = DbFunctions.AddMinutes(x.AddedOn, diffMinutes).Value,
Customer = (x.IsGuestCheckOut == true ? x.CustomerEmail : x.Customer.FirstName + " " + x.Customer.LastName),
Phone = x.Phone,
TotalAmount = x.TotalAmount,
OrderStatus = x.OrderStatus });
down the road some where condition and pagination is applied
Actually i misunderstood the error it is not
FUNCTION projectName.AddMinutes does not exist
but
FUNCTION databaseName.AddMinutes does not exist
I don't know what the issue is. Do i have any non-compatible driver/connector , I don't know.
To solve this problem i just created function with name AddMinutes, it calls DATE_ADD() function internally. function definition is as below
CREATE FUNCTION `AddMinutes`(actualDateTime datetime, minutesToAdd int)
RETURNS datetime
BEGIN
RETURN DATE_ADD(actualDateTime, INTERVAL minutesToAdd MINUTE);
END
I understand that this is not proper solution, but a HACK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With