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);
}
}