2012-08-06 267 views
2

我使用EF4.1刪除從我的數據庫中的對象:該對象無法刪除,因爲它在ObjectStateManager中找不到?

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

得到一個錯誤:

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

http://stackoverflow.com/questions/449740/error-the-object-cannot-be-deleted-because-it-was-not-found-in-the-objectstatem – Habib 2012-08-06 04:13:18

+0

解決方案:http:// stackoverflow .COM /問題/ 7791149 /的對象,不能待刪除 - 因爲,它 - 是未找到,在最objectstatemanager/19422173#19422173 – Kjartan 2013-10-17 08:58:55

回答

3

,如果你想刪除的心不是對象連接到你得到這個錯誤當前上下文。要獲取附加對象,您需要從上下文中的數據庫查詢對象,或者手動調用attach(在刪除之前)將對象放到上下文中。

相關問題