Hilmi
Hilmi

Reputation: 3439

DbContext VS ObjectContext

I used to use DbContext for all of my DB Models, until I read Ways to optimize Entity Framework, after following the steps I found my self forced to switch to ObjectContext instead, So, There were alot of code changes to be done, but I am not sure that I doing the right thing, specially after Googling the deference I've noticed that DbContext is newer and better than ObjectContext, and also I noticed that I lost alot of things while switching to ObjectContext like "Migrations" and "Find" Method and much more...

So, Is the right thing to change my code to use ObjectContext instead of DbContext to increase the speed by Pre-Generating the Views ? or am I doing something wrong ?

Upvotes: 4

Views: 5498

Answers (2)

Pawel
Pawel

Reputation: 31610

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

Upvotes: 2

Martin4ndersen
Martin4ndersen

Reputation: 2876

I would encourage you to use DbContext as it is a simplified version of the ObjectContext. If the DbContext is not suffice, the wrapped ObjectContext can be accessed from the DbContext:

((IObjectContextAdapter)dbContext).ObjectContext

The "Generate Views" option is also available for Code First (DbContext) in EF Power Tools. Right-click a file derived from DbContext and select "Entity Framework" => "Generate Views". For more information see Generating Pre-compiled Views

Upvotes: 0

Related Questions