Guest User

Untitled

a guest
May 6th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. EF 4.1 - Stored Procedure Not Inheriting Pending Transaction
  2. using (var tran = Connection.BeginTransaction(IsolationLevel.ReadUncommitted))
  3. {
  4. try
  5. {
  6. // Act.
  7. var result = controller.Create(something);
  8.  
  9. // Assert.
  10. Assert.IsNotNull(result);
  11. }
  12. catch (Exception exc)
  13. {
  14. Assert.Fail(exc.Message);
  15. }
  16. finally
  17. {
  18. tran.Rollback();
  19. Connection.Close();
  20. }
  21. }
  22.  
  23. var cmd = Database.Connection.CreateCommand();
  24. cmd.CommandType = CommandType.StoredProcedure;
  25. cmd.CommandText = "exec dbo.MySP @SomeParam";
  26. cmd.Parameters.Add(new SqlParameter { Value = "test", ParameterName = "SomeParam" });
  27.  
  28. using (var rdr = cmd.ExecuteReader()) <--- exception thrown here.
  29. {
  30. // code to read result sets.
  31. }
  32.  
  33. using (new TransactionScope(TransactionScopeOption.Required,
  34. new TransactionOptions
  35. {
  36. IsolationLevel = IsolationLevel.ReadUncommitted
  37. }))
  38.  
  39. using (var tran = Connection.BeginTransaction(IsolationLevel.ReadUncommitted))
  40. {
Advertisement
Add Comment
Please, Sign In to add comment