Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 702
  • 1.1k
  • 54k

Data not deleting from parent child table

Jun 4 2023 5:28 PM

Hello Team,

Please am trying to delete data from two table but is not working, kindly assist.

 public ActionResult DeleteStaff(int StaffId, int CompanyId)
        {
            try
            {
                ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
               var company = db.tblCompany.Where(x => x.CompanyId == CompanyId ).FirstOrDefault();
                var Staff = db.tblStaffs.Where(x => x.StaffId == StaffId ).FirstOrDefault();

db.tblCompany.Remove(company);
                db.tblStaffs.Remove(Staff);
                db.SaveChanges();
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }

        }


Answers (4)