本文介绍了存储更新,插入或删除语句会影响意外的行数(0)。自实体加载后,实体可能已被修改或删除。刷新ObjectStateManager条目。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
I m fetching the problem with updating record, when I debug my project then it made those changes in data, but its not saving the updated record and showing an error on db.SaveChanges();
The error is ;
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
代码:
Code :
[NonAction]
privateFinancilInstituteWrappergetData(int id)
{
FinancilInstituteWrapper temp = newFinancilInstituteWrapper();
var details = from i indb.IIDBS
join a indb.ACDBS
oni.Idequalsa.Id
join b indb.BIDBSoni.Idequalsb.Id
wherei.Id==id
selectnewFinancilInstituteWrapper
{
II = i,
AC = a,
BI = b
};
foreach (FinancilInstituteWrapper a in details)
{
temp.II = a.II;
temp.BI = a.BI;
temp.AC = a.AC;
}
return temp;
}
//
// GET: /FinancilInstitute/Edit/5
publicActionResult Edit(int id=0)
{
return View(getData(id));
}
//
// POST: /FinancilInstitute/Edit/5
[HttpPost]
publicActionResult Edit(FinancilInstituteWrapper wrapper)
{
// try
// {
if (ModelState.IsValid)
{
db.Entry(wrapper.II).State = EntityState.Modified;
db.Entry(wrapper.AC).State = EntityState.Modified;
db.Entry(wrapper.BI).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (OptimisticConcurrencyException)
{
}
returnRedirectToAction("Index");
}
// }
//catch
//{
return View(wrapper);
//}
}
任何人都可以帮我解决这个问题....
Can anyone help me solve this Problem….
推荐答案
这篇关于存储更新,插入或删除语句会影响意外的行数(0)。自实体加载后,实体可能已被修改或删除。刷新ObjectStateManager条目。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!