1
I was doing some tests with respect to transactions and I saw that if I perform a search of the data registered and not committed they are returned. In Entity Framework this doesn’t happen, and so I searched behind the scenes he works with transactions.
Does anyone know how I can get around this situation:
var conn = new SqlConnection(ConfigurationManager.
ConnectionStrings["connNorthwind"].ConnectionString);
conn.Open();
var transaction = conn.BeginTransaction();
string productName = "tEST1";
var commad1 = conn.CreateCommand();
commad1.Transaction = transaction;
var commad2 = conn.CreateCommand();
commad2.Transaction = transaction;
var commad3 = conn.CreateCommand();
commad3.Transaction = transaction;
commad1.CommandText = "INSERT products(ProductName, Discontinued)VALUES ('" + productName + "', 'true')";
commad1.ExecuteNonQuery();
commad2.CommandText = "INSERT products(ProductName, Discontinued)VALUES ('" + productName + "', 'true')";
commad2.ExecuteNonQuery();
commad3.CommandText = "SELECT * FROM products where ProductName like '%" + productName + "%'";
var reader = commad3.ExecuteReader(System.Data.CommandBehavior.SingleResult);
bool produtoExistente = false;
if (reader.HasRows)
{
produtoExistente = true;
}
Assert.IsFalse(produtoExistente);