DbContext uses the ObjectContext object internally, and the EF command makes it available as a protected property in case you ever need to go to the lower level API and sounds like it does here, so you can use or expand the required functions from the derived Dbcontext:
public class YourContext : DbContext { public void Detach(object entity) { ObjectContext.Detach(entity); } }
You can then call this method from your controller to detach the object.
Alternatively, you can change it to even have a richer API:
public class YourContext : DbContext { public void ChangeObjectState(object entity, EntityState entityState) { ObjectContext.ObjectStateManager.ChangeObjectState(entity, entityState); } }
Here's what the DbContext from the metadata looks like:
public class DbContext : IDisposable { protected System.Data.Objects.ObjectContext ObjectContext { get; } ... }
Morteza Manavi Nov 12 '10 at 19:36 2010-11-12 19:36
source share