伙计们,
环境:ASP.NET MVC 4,Razor
我正在为我的 Web 应用程序使用 SimpleMembership 提供程序。当用户请求注册时,我需要调用 WebSecurity.CreateUserAndAccount 并更新一些其他表。整个操作必须是事务性的。这是我的想法:
using (UsersContext ctx = new UsersContext()) {
using (TransactionScope scope = new TransactionScope()) {
// The following call creates its own context but will call ctx.SaveChanges() internally
WebSecurity.CreateUserAndAccount(...);
// update some other tables using ctx
...
ctx.SaveChanges();
scope.complete();
}
}
我觉得这应该可行。但是,我想就是否有更好的方法征求您的专家意见。
预先感谢您的帮助。
问候,
彼得