43

Possible Duplicate:
ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)

Should I use ObjectContext or DbContext? What's the best way?

Community
  • 1
  • 1
user669226
  • 661
  • 1
  • 7
  • 16

3 Answers3

26

I am currently using DbContext in a Database first situation and it is working fine. DbContext is NOT only for Code First development.

DbContext acts like a wrapper around the ObjectContext. Julie Lerman has a nice explanation, how you can access the ObjectContext that is inside of DbContext here. So if you decide to use DbContext, you can still solve things with ObjectContext if you need to.

DbContext simplifies common tasks. One example is the Find() method.

Product p = db.Products.Find(id);
ckonig
  • 1,234
  • 2
  • 17
  • 29
16

ObjectContext for version 4.0 when using a designer generated model and DbContext with a 4.1 Code First model.

Darren Lewis
  • 8,338
  • 3
  • 35
  • 55
2

It seems like when you use the designer generated model it automatically defaults to ObjectContext anyway

  • Only if you do not add another Code Generation Item. – ckonig Jun 12 '12 at 09:09
  • 2
    Add a DbContext Generator first and your model will use DbContext. If you first add POCO Entity Generator, then your entities will derive from ObjectContext. – zomf Jul 19 '12 at 07:19