0

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?

Sandip D
  • 103
  • 1
  • 14
  • 1
    i guess you should implement it in database. – RaniDevpr Dec 13 '17 at 16:07
  • I'm pretty sure that Entity Framework is geared more towards MSSQL. You could also eat the overhead, convert to `string` and compare. – Greg Dec 13 '17 at 16:09
  • Why does your `DiffHours` convert to `DiffDays`? What driver are you using? DevArt apparently supports `DiffDays` but not `DiffHours`. – NetMage Dec 13 '17 at 22:27
  • Have a look at this question: https://stackoverflow.com/questions/30235304/how-to-use-canonical-functions-in-entity-framework-and-mysql – Wurd Dec 15 '17 at 12:24
  • 1
    Calculate this difference on client side. – Slava Utesinov Dec 19 '17 at 07:46

0 Answers0