DbContext VS ObjectContext

I used DbContext for all my database models until I read the Entity Framework Optimization Methods after completing the steps that I had to switch to ObjectContext instead. So there have been a lot of code changes, but I'm not sure I'm doing the right thing, especially after Googling respects that I noticed that DbContext newer and better than ObjectContext , and I also noticed that I lost a lot of things by switching on ObjectContext , like Migrations and Find, and more ...

So, Is it right to change my code to use an ObjectContext instead of a DbContext to increase the speed by pre-creating the views? or am i doing something wrong?

+4
source share
2 answers

You do not need to switch to the ObjectContext to get pre-generated views. I created T4 templates to generate pre-generated views for CodeFirst. Take a look here: Entity platform initialization is SLOW - what can I do to get it started faster? T4 templates are available on Visual Studio Gallerry. Here is a link to my blog post describing how you can use and use them

+2
source

I would advise you to use DbContext as this is a simplified version of ObjectContext. If the DbContext is not enough, the streamlined ObjectContext can be obtained from the DbContext:

 ((IObjectContextAdapter)dbContext).ObjectContext 

The Create Views option is also available for First code (DbContext) in EF Power Tools. Right-click the file obtained from DbContext and select "Entity Framework" => "Create Views." See Creating Precompiled Views for more information.

+1
source

All Articles