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();
}
}
我有一種感覺,這應該工作。不過,我想就您是否有更好的方式徵求您的專家意見。
非常感謝您的幫助。
問候,
彼得