I have a table contains various columns including two DateTime column, Start and End.
How can I write a linq query over entity framework to find Duration.
I’m looking for a result like this: 2y 3m 2d 6h 4m 58s.
There’s also three important limitations:
- I can’t add function or sp to db
- I can’t add new calculated column to table
- I can’t do this operation in memory using loops like
foreachconsidering memory usage according to the huge number of records.
Any idea?
In your
Linq-to-entitiesquery, you can use EntityFunctions and the the DiffSeconds method to find the difference between two DateTime’s