Friday, January 17, 2014

Entity Framework Datetime comparison problem

Today I had a problem while trying to the 1st line as below, which actually returns records whose ts equals DateTime.Now. Once add .AsEnumerable(), it works. After googling around, it seems LINQ to Entity Framework won't change everything to SQL. Using .AsEnumerable() it will change to LINQ to Object.

1. db.[seeds].Where(s => s.ts < DateTime.Now)
2. db.[seeds]..AsEnumerable().Where(s => s.ts < DateTime.Now)

No comments: