CompiledQuery.Compile and repository

Last post 04-03-2009 6:55 PM by mmeisinger. 1 replies.

Sort Posts:

  • CompiledQuery.Compile and repository

    04-02-2009, 11:54 PM
    • Member
      526 point Member
    • Ruffone
    • Member since 09-20-2002, 10:53 AM
    • New York
    • Posts 137
    I am reading about compile queries (CompiledQuery.Compile) and was wondering if it would add anything to the repository and if it would what might be the best way to implemented it.
  • Re: CompiledQuery.Compile and repository

    04-03-2009, 6:55 PM
    • Member
      652 point Member
    • mmeisinger
    • Member since 03-08-2008, 12:46 AM
    • Posts 91

    great question
    i guess it really depends on the query

    so the CompiledQuery.Compile method will take the underlying expression tree and evaluate it down to code
    this helps the execution time of the query since it doesn't have to be evaluated prior to execution

    it does this at the time the method is "jit-ted" so you really only gain the performance after the first time the method is called (since the expression tree has to be evaluated first, of course)

    so back to my original point...
    if you have expressions that don't change (except for the values in your conditional statements) then it might be a candidate for "compiling" the query
    e.g. in the example it has Func<Northwind, string, IQueryable<Customer>> so the only things that can change are the reference to the Northwind data context and the string parameter

    if your expression changes the conditionals or adds joins etc... then clearly you can't compile it

    the next thing to look for is if the query is called enough times to make it worth your while
    if the query isn't called that frequently then it might not be worth it

    hope that helps

Page 1 of 1 (2 items)