我可以使用 ADO NET 实体数据模型创建事务吗?
是否可以在以下 try-catch 中使用 ADO NET 实体数据模型将一组语句作为事务执行?
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Customer c)
{
try
{
c.Created = DateTime.Now;
c.Active = true;
c.FullName = Request.Form["FirstName"];
db.AddToCustomer(c);
db.SaveChanges();
Log log = new Log();//another entity model object
log.Created = DateTime.Now;
log.Message =
string.Format(@"A new customer was created
with customerID {0}", c.CustomerID);
db.AddToLog(log);
db.SaveChanges();
return RedirectToAction("CreateSuccess", "Customer");
}
catch
{
return View();
}
}
任何想法将不胜感激。
is it possible on the following try-catch to execute a set of statements as a transaction using ADO NET Entity Data Model?
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Customer c)
{
try
{
c.Created = DateTime.Now;
c.Active = true;
c.FullName = Request.Form["FirstName"];
db.AddToCustomer(c);
db.SaveChanges();
Log log = new Log();//another entity model object
log.Created = DateTime.Now;
log.Message =
string.Format(@"A new customer was created
with customerID {0}", c.CustomerID);
db.AddToLog(log);
db.SaveChanges();
return RedirectToAction("CreateSuccess", "Customer");
}
catch
{
return View();
}
}
Any thoughts would be very appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)