Dbcontext

The DbContext API first shipped with Entity Framework version 4.1 and provides a more productive surface for working with the Entity Framework and can be used with the Code First, Database First, and Model First approaches.

Objectcontext

Core class within Entity Framework



Better newer older

Example

"Dbcontext is newer api which should polish developers experience when using most common tasks - simply the api is better designed but you still have to get objectcontext from dbcontext and use the older api if you want to use some more complex features"

from question  

Why to use DbContext and not ObjectContext

"Dbcontext api is easier to work with than objectcontext but both approaches use the former"

from question  

Entity Framework Code First with an existing database

"You want to replace data in perfil is a feature it is about objectcontext api but the same is true or worse with dbcontext api"

from question  

Entity Behavior in Entity Framework is very strange

"There are many reasons why the dbcontext api is better than the older objectcontext api but in your case it may initially feel like a downgrade"

from question  

What is the recommended method of explict loading in Entity Framework 6 from a partial class?

"The dbcontext is a smaller api exposing the most commonly used;features of the objectcontext"

from question  

What's the difference between DbContext and ObjectContext

"My understanding is that although dbcontext is newer it s not necessarily better than objectcontext it just provides a different api that might be considered simpler but doesn t that depend on the use case"

from question  

Entity Framework: Providing both DbContext and ObjectContext APIs in shared assembly

Simpler common development

Example

"Dbcontext is much simpler to use than objectcontext and will serve the most common development needs"

from question  

Using DbContext API instead of ObjectContext API with Entity Data Model

"And dbcontext is much simpler to use than objectcontext and will serve the most common development needs"

from question  

Unable to find model and context class files while using Database first approach

Pleasant api easier

Example

"Besides the dbcontext api is easier to use than objectcontext"

from question  

Linq doubts with DB context

"Dbcontext is a much more pleasant api than objectcontext"

from question  

Why I can't call DbContext.ObjectContext directly?

Others

Example

Because of that i think that whole idea of dbcontext api was management failure;at the moment ado.net team must maintain two apis - dbcontext is not mature to replace objectcontext and it actually can t because it is just a wrapper and because of that objectcontext cannot die

from question  

Why does EF 4.1 not support complex queries as well as linq-to-sql?

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.

from question  

DbContext VS ObjectContext

Despite the fact that the incident entity had an entitystate of unchanged objectcontext still recognised it as new;dbcontext seems much more state aware

from question  

ObjectContext with Entity Framework 6 inserting duplicates on existing related entities

You just need to connect using the entity framework driver and if you develop in any of technologies that uses dbcontext includes code first model first and data base first but is lighter than objectcontext you can use the list below

from question  

Can I use CTP5 DBContext with LINQPad?

Now my answer is mostly - for new users dbcontext api is probably better;dbcontext api is simplified - both in terms of usage and features but you can still get objectcontext from dbcontext and use features available only in objectcontext api

from question  

Using DbContext and Database First in EF 4.1

It discovers entity sets based on dbset properties defined on the dbcontext derived class or in general it discovers your model based on your code;objectcontext does not do any discovery and is not convention based

from question  

Automatic properties: DBSet vs ObjectSet

If adding 2000 entities and saving the changes at the end dbcontext is 3 to 5 times slower than objectcontext btw. i know that adding a large amount of entities would be better using sqlbulkcopy but that s not the point

from question  

DbContext is very slow when adding and deleting

When it comes to deletion it even gets worse when saving at the end of all entity removals dbcontext is around 18 times slower than objectcontext

from question  

DbContext is very slow when adding and deleting

In 6.7 a graph it shown that states that the performance of a objectcontext linq query is better than dbcontext linq query

from question  

Performance DbContext Linq Query versus ObjectContext Linq Query

Actually dbcontext is just a layer on top of objectcontext;dbcontext api has much nicer smaller api and is easier to work with

from question  

Is ObjectContext deprecated in .NET 4.5?

A shared dbcontext is not a good idea;since dbcontext objectcontext is not thread safe

from question  

What is the MembershipProvider life cycle?

Back to Home
Data comes from Stack Exchange with CC-BY-SA-4.0