The object cannot be deleted because it was not found in the ObjectStateManager?

c#-4.0 entity-framework

Question

I am using EF4.1 to delete an object from my db:

public virtual void Delete(T entity)
{
  _entities.CreateObjectSet<T>().DeleteObject(entity);
}

getting an error:

The object cannot be deleted because it was not found in the ObjectStateManager
1
2
8/6/2012 3:25:39 AM

Popular Answer

You get this error if the object you are trying to delete isnt attached to the current context. To get attached objects you either need to query the object from the db on the context, or manually call attach (before delete) to put the object onto the context.

3
8/6/2012 4:03:47 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow