I have a new .NET 4.0 console application that uses:
So far
Try this, Create transaction after creating context.
public static void TestInsert()
{
using (var context = new MyDbContext())
{
using (TransactionScope scope = new TransactionScope())
{
// Create a test user
DateTime dt = DateTime.Now;
var user1 = new User { UserID = 1, UserName = "test" };
context.Users.Add(user1);
context.SaveChanges();
scope.Complete();
}
}
}
Kindly complete the scope.
The Complete method commits the transaction. If an exception has been thrown,
Complete is not called and the transaction is rolled back.
scope.Complete();
See MSDN.