Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ C#4.0
I an new in linq i want to use commit rollback tsql in linq using c# 4.0
Posted 15-May-12 22:14pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

before any changes occure on the database you have to have a db.submitchanges() before the changes are submitted. Anything that happens in the mean-time will be held in a transaction anyway. :
 
 
public void ChangeData(string newData)
{
 
            //Always use a new instance of the DataContext when making changes to the data as all changes made would be submitted otherwise
            DataContext1 db = new DataContext1();
 
            //throws an error if it find 0 or >1 record.  can be useful
            data recordToUpdate = db.datas.Where(d => d.data_id == id).Single();
 
            //change data in the record instance.  Remember that this record is tied to the db instance of the database.  No other instance contains this change
            recordToUpdate.email_address = newData;
 
            try
            {
                //you could leave out the try and catch the error higher up
                db.SubmitChanges();
            }
            catch
            {
                //notify? raise error?
            }
  //once db loses scope the changes vanish with it
}
 
Just remember that with link to sql, no actual changes happen until you try to submit the changes to that db instance
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If I understood the question correctly, you should use the TransactionScope Class[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 250
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,177
2 Maciej Los 3,774
3 Peter Leow 3,478
4 CHill60 2,702


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 13 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100