【发布时间】:2011-12-01 15:43:09
【问题描述】:
使用 MVC 创建 Player 类型的数据库条目:
[HttpPost]
public ActionResult Create(FormCollection fc, Player player)
{
players.Players.InsertOnSubmit(player);
players.SubmitChanges();
Errors errors;
if (!IsValid(player, out errors))
{
ViewBag.Errors = errors;
return RedirectToAction("Edit", player);
}
return Redirect("/Home/Players");
}
[HttpPost]
public ActionResult Edit(FormCollection fc, Player player)
{
players.SubmitChanges();
return Redirect("/Home/Players");
}
我的问题是 Edit 方法中的 players.SubmitChanges() 不会更改数据库中的任何内容。在创建作品中使用InsertObSubmit。我要不要换一种方式?
【问题讨论】:
-
player未附加到数据库。此外,这与 MVC 无关,而是与 Linq-to-SQL 或实体框架相关。 :) -
我应该如何以及在哪里将播放器附加到数据库?我假设它会知道它属于哪里,因为 Player 具有 global::System.Data.Linq.Mapping.TableAttribute(Name) 属性集。
标签: .net entity-framework linq-to-sql