locked
Compiled Query Does not work as concept RRS feed

  • Question

  • Dear All,

    I am using LINQ with Entities

    I am executing  same query with different parameter in a for loop. So I decided to Prepare that query as compiled query and then call the compiled query. I did the same in the following manner but there is no difference in time when query execute first or then after … Please suggest where I gone wrong.

    As query was executing in DAL layer. So I create my own DAL class Called ABC.cs  in DAL.

    In that  First I create global variable for compiled as

     

    public static  Func<datacontext , DateTime, string, IQueryable<tmpclass >> compiledQuery;

     

     

    Then I assigned the compiled veriable in the constructor of DAL class

     

    static ABC()

            {

               

                compiledQuery = System.Data.Objects.CompiledQuery.Compile<datacontext, DateTime, string, IQueryable< tmpclass >>(

                               (ctx, orderDate, shemecode) => (from dsp1 in ctx.table1 where dsp1.NAVDATE <= orderDate && dsp1.SCHEMECODE == shemecode

    orderby dsp1.NAVDATE  descending                                                           select new Quartile_tmp_dt  { newbasedt= dsp1.NAVDATE }));

            }

     

     

     

     

    Then I am invoking  it as

     

     

     

      using (DataContext AWEntities = new Datacontext())

    {

     AWEntities.Tables1.MergeOption =System.Data.Objects.MergeOption.NoTracking;

     AWEntities.Tables1.MergeOption = System.Data.Objects.MergeOption.NoTracking;

     

    foreach (var item in result)

     {

    DateTime frdt = Convert.ToDateTime(frmDate);

    var res = compiledQuery.Invoke(AWEntities, frdt, item.SCHEMECODE);

    }

    }

    Wednesday, June 22, 2011 5:26 PM

Answers

  • Hi,

    I'm not sure what you mean with "time when query execute first or then after".. What do you mean with first and then after? First is that without compiled and after is with?

    Since your query is quite simple, my guesses is that you don't get any measureable results in a compiled query compared to without.

    Try to use a more complex query with lots of joins etc, and then check.


    --Rune
    • Proposed as answer by Jackie-Sun Monday, July 4, 2011 5:08 AM
    • Marked as answer by Jackie-Sun Monday, July 11, 2011 10:02 AM
    Thursday, June 23, 2011 7:41 AM

All replies

  • Hey Is any one has any idea
    Thursday, June 23, 2011 7:17 AM
  • Hi,

    I'm not sure what you mean with "time when query execute first or then after".. What do you mean with first and then after? First is that without compiled and after is with?

    Since your query is quite simple, my guesses is that you don't get any measureable results in a compiled query compared to without.

    Try to use a more complex query with lots of joins etc, and then check.


    --Rune
    • Proposed as answer by Jackie-Sun Monday, July 4, 2011 5:08 AM
    • Marked as answer by Jackie-Sun Monday, July 11, 2011 10:02 AM
    Thursday, June 23, 2011 7:41 AM