I recently ran into a problem trying to complete some transaction related operations of both WebSecurity and DbContext.
In my ASP.NET MVC 4 application, I am trying to register a new user this way:
var transactionOptions = new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TransactionManager.MaximumTimeout
};
using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
var confirmationToken = WebSecurity.CreateUserAndAccount(
vm.Email,
vm.Password,
new
{
AccountCreationDate = DateTime.Now,
City = vm.City,
(...)
},
true);
Roles.AddUserToRole(vm.Email, "Client");
var userRepository = new UserRepository();
userRepository.AssignData(vm.Email);
transactionScope.Complete();
}
code>
As you can see, I am trying to create a user account and membership, assign a role, and then do some additional things in Eb5 DbContext through the repository.
This code is wrapped in a try-catch block, which I am not here for brevity.
And here is my question: is it possible to wrap all these 3 calls to the database (via WebSecurity, Roles and Repository, respectively) using one transaction WITHOUT allowing its escalation to DTC?
I am using SQL Server 2012, one DB and the same connection string, if that helps.