小李先生(xiaooolixiansheng)

不积跬步,无以至千里!&&不破不立!

导航

刪除表實體問題

錯誤提示:

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

 

原来是因为DeleteObject方法必须是先关联实体,或者实体来自查询。

 

刪除集合:

List<UPLOAD_FILES> lstFile = comm.GetFiles(model.HRTrainings.FormNo);

 foreach (var item in lstFile)

 {

     model.file = item;

     db.UploadFiles.Attach(model.file);//此句為重點

     db.UploadFiles.Remove(model.file);

 }

 

 參照:http://www.cnblogs.com/Benjamin/archive/2012/10/24/2736739.html

posted on 2016-01-29 11:25  小李先生  阅读(136)  评论(0编辑  收藏  举报