Alvin
Alvin

Reputation: 8519

Calculate mins in Linq

I am trying to do this to calculate the LastDate is more then 15 mins in LINQ:

And DateTimeOffset.Now.Subtract(tbl.LastDate).Minutes >= 15

I got this error:

Method 'System.TimeSpan Subtract(System.DateTimeOffset)' has no supported translation to SQL.

Upvotes: 2

Views: 97

Answers (1)

Anik Saha
Anik Saha

Reputation: 4494

You can use the EntityFunctions class to perform operations on dates, among other things.

And (tbl.LastDate >= EntityFunctions.AddMinutes(DateTime.Now, -15))

if you are not using entityfunction you can do that

DateTime oldestDate = DateTime.Now.AddMinutes(-15);

... then modified the where portion of the LINQ query

And (tbl.LastDate >= oldestDate )

Upvotes: 1

Related Questions