1

I am working on Compiled Queries to improve the performance of the LINQ queries. I defined a separate class & written a function :-

 public static Func<ApplicationDbContext, IQueryable<EmployeeDetail>>
           CompliedQueryForEmployee = 
CompiledQuery.Compile((ApplicationDbContext context) => from c in 
context.tblEmployee select c);

If I use DataContext above then while using the above function it gives error as Invalid arguments.

This is how I access the tables :-

 using (var ctx = new ApplicationDbContext(schemaName))
{
....
ctx.tblEmployee.ToList();
}

Exactly how to write & use compiled Queries?

Anup
  • 9,396
  • 16
  • 74
  • 138
  • Possible duplicate of [Entity Framework Compiled Query](http://stackoverflow.com/questions/9739925/entity-framework-compiled-query) – jrummell Jul 07 '16 at 12:42

1 Answers1

4

Compiled Queries, as you are using them, come from LINQ to SQL (DataContext) and Entity Framework pre-Code First (ObjectContect). Entity Framework Code First (DbContext and ApplicationDbContext) do not use them, or, rather, LINQ queries are always compiled and cached the first time they are used. See https://msdn.microsoft.com/en-gb/data/hh949853.aspx.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74