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

c#-4.0 entity-framework

Question

I'm deleting an item from my database using EF4.1:

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

obtaining a mistake:

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

Popular Answer

If the item you are attempting to remove is not connected to the current context, you will see this error. You must either explicitly execute attach (before delete) to add the object to the context in order to get associated objects or query the object from the database on 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