Compiled query returns the same every time

I have this compiled request:

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 the DeletionDate object is set to db, it still returns the same object - I expect null. (It returns zero, as expected, after disposing of the application pool.)

For some reason, it works when I use the next 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)
);
+3
source share
1 answer

DateTime.UtcNow , SQL. , , (.. ) , .

, .

SQL, , .

+2

Source: https://habr.com/ru/post/1734163/


All Articles