有人能帮帮忙吗?
我的控制器中有create操作:
public class MovieController : Controller
{
Connect connection = new Connect();
Movie movie = new Movie();
[HttpPost]
public ActionResult Create(Movie moviecreated)
{
try
{
// TODO: Add insert logic here
connection.Connection().AddObject(moviecreated);
connection.Connection().Context.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View(movie);
}
}
}我的连接类
public class Connect
{
public ObjectSet<Movie> Connection()
{
var connStr = ConfigurationManager.ConnectionStrings["Entities"];
ObjectContext context = new ObjectContext(connStr.ConnectionString);
var movieContext = context.CreateObjectSet<Movie>();
return movieContext;
}
}它没有保存新添加的内容,我哪里错了?非常感谢。
发布于 2012-07-12 20:36:25
每次调用instance.Once ()时,它都会创建另一个连接,然后再添加一个新记录,然后尝试保存不同的上下文。将其更改为属性,然后保存您的上下文。
https://stackoverflow.com/questions/11451110
复制相似问题