Linq, isolation level

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • imbirek8

    Linq, isolation level

    Hi, I wrote code that would read data from db in readUncommited isolation
    level.
    I'm not sure, that I've done and understand it correctly, could you see my
    code and tell your opinion ?
    Can I define two scope in different isolation level in one transaction ?

    class Program
    {
    static void Main(string[] args)
    {
    try
    {
    string connectionStrin g = "Data
    Source=WIN2003\ \SQLEXPRESS;Ini tial Catalog=test;In tegrated Security=True";
    DataClassesData Context db = new
    DataClassesData Context(connect ionString); //declare my connection
    TransactionOpti ons option = new TransactionOpti ons()
    //declare my isolation level
    {
    IsolationLevel =
    System.Transact ions.IsolationL evel.ReadUncomm itted
    };
    TransactionScop e scope = new
    TransactionScop e(TransactionSc opeOption.Requi red, option); //create
    transaction scope
    Operation(db); //do something
    scope.Complete( ); //commit transactionScop e, but not
    transaction

    TransactionScop e scope2 = new
    TransactionScop e(TransactionSc opeOption.Requi red, option); //create another
    scope, but I use TransactionScop eOption.Require d so I use the same
    transaction
    Operation(db); //do something
    scope2.Complete (); //commit this scope

    db.SubmitChange s(); //here I commit all transaction
    }
    catch (Exception e)
    {
    db.Dispose(); //rollBack all transaction
    }
    }
    public static void Operation(DataC lassesDataConte xt db)
    {
    var select = from u in db.tUsers
    where u.userId == 1
    select u;
    List<tUserlista Tmp = new List<tUser>(sel ect);
    foreach (var u in listaTmp)
    Console.WriteLi ne(u.userName);
    }
    }

    Thank you for help

Working...