Alvin Alvin - 4 years ago 282
Vb.net Question

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.

Answer Source

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 )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download