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

Quality Example
Newer

"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"

Api easier

"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"

Worse

"It 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"

Api better

"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?"

Newer api

"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"

Simpler common development

Quality Example
Much simpler

"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"

"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"

Pleasant api easier

Quality Example
Api easier

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

from question "Linq doubts with DB context"

More pleasant api

"Dbcontext is a much more pleasant api than objectcontext"

from question "Why I can't call DbContext.ObjectContext directly?"

Others

Quality Example
Better

"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"

"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"

Slower

"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"

Lighter

"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?"

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