DateTime.Now in Compiled Queries RRS feed

  • Question

  • I have just done a test where I use DateTime.Now in a compiled query.  It appears to "freeze" the intial value of DateTime.Now into the query.  I.e. it gets the time value as at the compilation/intitial execution, and then it uses that value in all subsequent executions of the query.

    Is that "by design"?  If so, is the behavior documented somewhere, so that I can make sure I understand it and don't get into trouble using times in queries?

    (I'm presuming the solution is to pass the current time in as a parameter.)

    John Rusk, - .NET and Agility
    Tuesday, August 4, 2009 1:30 AM


  • The idea behind compiled query is that the query is parsed, compiled and resolved except for the parameters to Compile itself.

    If this was not the case and every single reference had to be resolved on every use then most of the benefit of CompiledQuery would be lost.

    • Marked as answer by John Rusk Tuesday, August 4, 2009 10:16 PM
    Tuesday, August 4, 2009 3:18 AM