1
使用带有活动记录的ASP MVC。ASP MVC只删除2个表之间的关系(多对多关系)
Ive得到了2桌与有时是相关的,有时是不记录。该关系由用户定义。 1个表具有项目,另一个具有设备。项目可以创建和删除,设备不能。当用户删除项目时,该项目与设备之间的所有关系都应该被删除,但设备应该保留。
我该怎么做?
我的删除操作,目前看起来是这样的:
public ActionResult Delete(int id, FormCollection collection)
{
if (!Project.Exists(id)) return RedirectToAction("Index/1", "Error");
try
{
Project project = Project.Find(id);
if (project.User.Id != SessionVariables.AuthenticatedUser.Id) return RedirectToAction("Index/1", "Error");
project.DeleteAndFlush();
return RedirectToAction("Index", "Project");
}
catch(Exception e)
{
return RedirectToAction("Index", "Error");
}
}
这实际上与MVC有什么关系? – 2010-10-08 08:05:28