top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between DbContext and ObjectContext?

+3 votes
1,490 views
What is the difference between DbContext and ObjectContext?
posted Mar 30, 2015 by Muskan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

DbContext is a lightweight version of the ObjectContext class, which is laid almost right on top of ObjectContext (there is even a way to get to the ObjectContext from just the DbContext).
It's also a lot easier to use, IMO, and makes CRUD operations a sinch.

ObjectContext

ObjectContext is a class that manages all the database operations, like database connection, and manages various entities of the Entity Model. We can say that ObjectContext is the primary class for accessing or working together with entities that are defined in the conceptual model.

ObjectContext is responsible for:

  1. Database connection
  2. It provides builtin Add, Update and Delete functions
  3. Object Set of every entity
  4. Provide State of pending changes
  5. It holds the changes done in entities

DbContext

DbContext is conceptually similar to ObjectContext. DbContext is nothing but a ObjectContext wrapper, we can say it is a lightweight alternative to the ObjectContext. DbContext can be used for DataBase first, code first and model first development. DbContext mainly contains a set of APIs that are very easy to use. The API is exposed by ObjectContext. These APIs also allow us to use a Code First approach that ObjectContext does not allow.

For More: http://thedatafarm.com/data-access/accessing-objectcontext-features-from-ef-4-1-dbcontext/

answer Mar 30, 2015 by Amit Kumar Pandey
...