0
伙计们,SimpleMembership - 正确的方式来创建一个交易
管环境:ASP.NET MVC 4,剃刀
我使用SimpleMembership提供商我的Web应用程序。当用户请求注册时,我需要调用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();
}
}
我有一种感觉,这应该工作。不过,我想就您是否有更好的方式征求您的专家意见。
非常感谢您的帮助。
问候,
彼得