我正在使用 EF4.1 从数据库中删除对象:
public virtual void Delete(T entity)
{
_entities.CreateObjectSet<T>().DeleteObject(entity);
}
出现错误:
The object cannot be deleted because it was not found in the ObjectStateManager
最佳答案
如果您尝试删除的对象未附加到当前上下文,则会出现此错误。要获取附加对象,您需要从上下文中的数据库查询对象,或者手动调用附加(在删除之前)将对象放入上下文中。
关于entity-framework - 无法删除该对象,因为在 ObjectStateManager 中未找到该对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822207/