0

I tried to write compiled query as given below:

public static Func<MyDBEntities, string, List<Client>> getCustomers =
CompiledQuery.Compile(
(MyDBEntities ctx, string strCustCode) => from objCustomer in ctx.Clients
     select objCustomer);

and getting following error message:

Creates a new delegate that represent the complied LINQ to Entity query

Error:

There is no implicit reference conversion from MyDBEntities to System.Data.Objects.ObjectsContext

I'm using DbContext in this project.

Didn't understand what was missed.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sukhjeevan
  • 3,074
  • 9
  • 46
  • 89

1 Answers1

1

There's no way to use CompiledQuery when you're using the DbContext API; CompiledQuery works only with ObjectContext. If you're using Code First, you're most likely using the DbContext API. And Microsoft recommends that you use the DbContext API in new projects even if you'll be working with Database First or Model First models.

But if you use EF5, it brings auto-compiled queries, which work very differently than CompiledQuery. Instead of your writing code to compile each query and then invoking each as needed, EF5 caches the generated SQL for you as a background process, then searches the cache for already compiled queries when you execute any query.

See:

http://blogs.msdn.com/b/adonet/archive/2012/02/14/sneak-preview-entity-framework-5-0-performance-improvements.aspx

and

http://www.devproconnections.com/article/entity-framework/entity-framework-5-143875

Taken from: Entity Framework Compiled Query

Community
  • 1
  • 1
Moeri
  • 9,104
  • 5
  • 43
  • 56