2

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.
Alvin
  • 8,219
  • 25
  • 96
  • 177

1 Answers1

1

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 )
Anik Saha
  • 4,313
  • 2
  • 26
  • 41
  • EntityFunctions is not declare, I am using .net 4.0 – Alvin Dec 30 '15 at 05:05
  • I tried this => And tbl.LastDate >= DateTimeOffset.Now.AddMinutes(-15), I think it should be the same like your answer? – Alvin Dec 30 '15 at 05:23
  • I dont calculate it in linq. After calcuating it do you get right answer or not? Calcutating linq may give you exception. – Anik Saha Dec 30 '15 at 05:31