Getting an exception while calculating difference between two dates in Linq

350 Views Asked by At

I am trying to get the duration between two dates in mysql.

I have observed that there is DbFunctions class which can calculate difference between two dates in different forms like days, hours, microseconds and many more.

I am using MySQL as dabatase and EF6. I have used DbFunctions as below as below.

await (from o in Order
  select new
  {
      ID = o.ID,
      OrderBookTime = o.OrderDateTime,
      DelieveryTime = DbFunctions.DiffHours(o.DeliveryDateTime, o.OrderDateTime),
  }).ToListAsync();

It throws an exception as FUNCTION database_name.DiffDays does not exist

I have checked the query executed in the background.

SELECT
`Extent1`.`ID`, 
`Extent1`.`OrderDateTime`,
DiffHours(`Extent1`.`DeliveryDateTime`, `Extent1`.`OrderDateTime`) AS `C1`, 
FROM `order` AS `Extent1`

Is it necessary to write custom function in the database which will calculate the difference for tow dates?

0

There are 0 best solutions below