Saturday, August 28, 2010

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

You are writing this:

from a in context.People
from b in context.People
where a.BirthDate.Subtract(b.BirthDate).TotalDays < 1
select new { a, b };

You receive the error:

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

You should be writing this:

from a in context.People
from b in context.People
where (a.BirthDate - b.BirthDate).TotalDays < 1
select new { a, b };

2 comments:

  1. Legend, thanks!

    ReplyDelete
  2. Thanks! Straight to the point :)

    ReplyDelete