昨天我在管理员端的控制器中应用了以下代码
public ActionResult Delete(tblGroup Group)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("InsUpsDelTbl_Group"))
{
try
{
//Newly added code start
var grp = db.tblGroups.FirstOrDefault(g => g.GroupID == Group.GroupID);
if (grp!=null && grp.tblSubGroups.Count>0)
{
TempData["AlreadyExist"] = "This Group Name can not be deleted as its enities are bind with SubGroups";
}
//Newly added code end
else
{
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("@Operation", "Delete");
cmd.Parameters.AddWithValue("@GroupID", Group.GroupID);
cmd.ExecuteScalar();
TempData["Delete"] = "Group Name Deleted Successfully";
con.Close();
}
}
catch (Exception ex)
{ throw ex; }
}
}
//return RedirectToAction("Index");
return RedirectToAction("Index");
}
这是为了验证关于主键和外键关系以及我在模型中给出关系并且还更改数据库。 这个东西在我的本地运行正常,但是在更新测试服务器上的数据库+应用程序并点击删除之后就会出现问题
答案 0 :(得分:0)
即。 ABC到XYZ