none
How to get the DbContext of an Entity RRS feed

  • Question

  • Hi,

    I use different DbContext for objects, because when I want to change and save some data from my current data entry process and don't want to save current changes! so I want get the DbContext of an entity that currently attached to, to call SaveChanges method of that DbContext.

    how can I do it?


    Amin Mashayekhi

    Tuesday, January 28, 2014 12:28 PM

Answers

  • Hello,

    If I understand correctly, you want to get the dbcontext object from an entity object.

    Unfortunately, for DbContext, it is impossible since its entities do not implement EntityObject and with DbContext, we cannot make it implement EntityObject obligatorily or it will throw an error.

    The workaround is worked however it is used for ObjectContext:

    http://blogs.msdn.com/b/alexj/archive/2009/06/08/tip-24-how-to-get-the-objectcontext-from-an-entity.aspx

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 29, 2014 4:20 AM
    Moderator