Problems with Transaction Scope
Posted: Tue 09 Jun 2009 15:55
Hi,
I'm trying to use TransactionScope:
case 1: Not found
using (miContexto Context = new miContexto())
{
using (TransactionScope tran = new TransactionScope())
{
//step1 : this function returns a code
string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;
//step2 : insert many rows in Table1 table
foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}
Context.SaveChanges(false );
//step 3: this function uses the rows that are inserted in step 2, but it doesn't find data
string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;
tran.Complete();
Context.AcceptAllChanges();
}
}
case 2: found ok (it hasn't transaction control)
using (miContexto Context = new miContexto())
{
string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;
foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}
Context.SaveChanges();
string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;
}
}
________
COCAINE REHAB ADVICE
I'm trying to use TransactionScope:
case 1: Not found
using (miContexto Context = new miContexto())
{
using (TransactionScope tran = new TransactionScope())
{
//step1 : this function returns a code
string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;
//step2 : insert many rows in Table1 table
foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}
Context.SaveChanges(false );
//step 3: this function uses the rows that are inserted in step 2, but it doesn't find data
string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;
tran.Complete();
Context.AcceptAllChanges();
}
}
case 2: found ok (it hasn't transaction control)
using (miContexto Context = new miContexto())
{
string strAux = Context.F_Import1(null,"a").ToList()[0].codigo;
foreach(string str2 in lineas)
{
Table1 aux = new Table1();
aux.Nombre = str2;
aux.cod = strAux;
Context.AddTable1(aux);
}
Context.SaveChanges();
string strAux2 = Context.F_Import2(null,"a").ToList()[0].codigo;
}
}
________
COCAINE REHAB ADVICE