I have this compiled query:
private static Func<DBContext, Foo> FooQuery = CompiledQuery.Compile<DBContext, Foo>(
_db => _db.FooTable.SingleOrDefault(f => f.DeletionDate == null || f.DeletionDate > DateTime.UtcNow)
);
When I run it once, it returns the expected Foo object.
But then, even after that object's DeletionDate is set in the db, it still returns the same object -- I am expecting null. (It returns null, as expected, after recycling the app pool.)
For some reason, it works when I use the following compiled query instead (and pass in DateTime.UtcNow), but I'm not sure why.
private static Func<DBContext, DateTime, Foo> FooQuery = CompiledQuery.Compile<DBContext, DateTime, Foo>(
(_db, now) => _db.FooTable.SingleOrDefault(f => f.DeletionDate == null || f.DeletionDate > now)
);