locked
dbcontext vs objectcontext RRS feed

  • Question

  • Hi

    We have to new project using entity framework should we use dbcontext or objectcontext for entity class.

    thanks


    sahil

    Sunday, September 30, 2012 3:04 AM

Answers

  • Hi sahil2009;

    You should be using DbContext. DbContext is a light weight version of the ObjectContext. If you find yourself needing something that is in ObjectContext that is not exposed by DbContext you can always get a hold of the ObjectContext by doing the following:

    ObjectContext myObjectContext = (myDbContextInstance as IObjectContextAdapter).ObjectContext;

    Where myDbContextInstanse is you instance of the DbContext.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Bob Shen Monday, October 8, 2012 10:40 AM
    Sunday, September 30, 2012 3:34 AM
  • Hello, Following link might help

    http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/01aac967-5b31-45ee-ac72-9095d9f2494c

    Regards


    please Mark as the Answer, If this answers your question. If this post is helpful, please vote as helpful.

    • Marked as answer by Bob Shen Monday, October 8, 2012 10:40 AM
    Sunday, September 30, 2012 3:31 AM

All replies

  • Hello, Following link might help

    http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/01aac967-5b31-45ee-ac72-9095d9f2494c

    Regards


    please Mark as the Answer, If this answers your question. If this post is helpful, please vote as helpful.

    • Marked as answer by Bob Shen Monday, October 8, 2012 10:40 AM
    Sunday, September 30, 2012 3:31 AM
  • Hi sahil2009;

    You should be using DbContext. DbContext is a light weight version of the ObjectContext. If you find yourself needing something that is in ObjectContext that is not exposed by DbContext you can always get a hold of the ObjectContext by doing the following:

    ObjectContext myObjectContext = (myDbContextInstance as IObjectContextAdapter).ObjectContext;

    Where myDbContextInstanse is you instance of the DbContext.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Bob Shen Monday, October 8, 2012 10:40 AM
    Sunday, September 30, 2012 3:34 AM