【发布时间】:2011-04-22 07:26:27
【问题描述】:
使用带有活动记录的 ASP MVC。
我有 2 个表,其中的记录有时相关,有时不相关。关系由用户定义。一张桌子有项目,另一张桌子有设备。可以创建和删除项目,设备不能。当用户删除一个项目时,该项目与设备之间的所有关系都应删除,但设备应保留。
我该怎么做?
我的删除操作目前如下所示:
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 有什么关系?
标签: sql asp.net-mvc database database-relations