ASP.NET - Store update, insert, or delete statement affected an unexpected number of rows (0).

Asked By Sameer Khan on 04-Sep-13 01:09 AM
Hi,
My application is in Asp.net MVC3 coded in C#.Net, I have a master and one detail on my view.
The issue im facing is whenever i try to edit (update) the records, then i get this error 

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.
but i dont get this error when i save the record first time, i get this problem only when im editing the record.
[HttPost]
public ActionResult Edit(Mirror_Applicant_Master_Details Mirror_Applicant_Master_Details_Obj)
    {
db.Mirror_Applicant_Details.Attach(Mirror_Applicant_Master_Details_Obj.obj_Applicant_Details);
          db.ObjectStateManager.ChangeObjectState(Mirror_Applicant_Master_Details_Obj.obj_Applicant_Details, EntityState.Modified);
          db.SaveChanges();
            
          if (Mirror_Applicant_Master_Details_Obj.obj_Applicant_Equipments != null)
{
            
            foreach (var item in get_Equipments)
            {
              item.Applicant_ID = Mirror_Applicant_Master_Details_Obj.obj_Applicant_Details.Applicant_ID;
              item.Delete_Flag = false;
              db.Mirror_Applicant_Equipment_Master.Attach(item);
              db.ObjectStateManager.ChangeObjectState(item, EntityState.Modified);
               db.SaveChanges();
            }
          }