locked
In what situations we should use ObjectContext and not DbContext? RRS feed

  • Question

  • Hi all,

    I am learning about EF and have read a lot about the subject. At one point you geta little confused :)

    I am curious about in what situations we should use ObjectContext and not DbContext?

    Thank you


    Max
    Wednesday, October 26, 2011 3:24 PM

Answers

  • Hi,

    See http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx and in particular from the Remarks paragraph :

    "DbContext wraps ObjectContext and exposes the most commonly used features of ObjectContext by using simplified and more intuitive APIs. You can access the underlying ObjectContext whenever you need to use features that are not supported by DbContext. For more information, see What’s Not Supported."

    My understanding is that DbContext is to support the "new" Code First feature introduced in EF 4.1. So IMO when you see DbContext it should be the "code first" model when using ObjectContext it should be the "model first" (or "database first") approach.

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by Maximusdm Friday, October 28, 2011 3:33 AM
    Wednesday, October 26, 2011 3:43 PM

All replies

  • Hi,

    See http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx and in particular from the Remarks paragraph :

    "DbContext wraps ObjectContext and exposes the most commonly used features of ObjectContext by using simplified and more intuitive APIs. You can access the underlying ObjectContext whenever you need to use features that are not supported by DbContext. For more information, see What’s Not Supported."

    My understanding is that DbContext is to support the "new" Code First feature introduced in EF 4.1. So IMO when you see DbContext it should be the "code first" model when using ObjectContext it should be the "model first" (or "database first") approach.

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Marked as answer by Maximusdm Friday, October 28, 2011 3:33 AM
    Wednesday, October 26, 2011 3:43 PM
  • I marked as an answer but do not assume that DbContext is to support the new Code First. -- that is not true :)

    Thanks


    Max
    Friday, October 28, 2011 3:35 AM