c# - How to rollback a transaction in Entity Framework -



c# - How to rollback a transaction in Entity Framework -

string[] userstoadd = new string[] { "asd", "asdert", "gasdff6" }; using (entities context = new entities()) { foreach (string user in userstoadd) { context.addtousers(new user { name = user }); } seek { context.savechanges(); //exception thrown: user 'gasdff6' exist. } grab (exception e) { //roll changes including 2 previous users. }

or maybe done automatically, meaning if error occurs, committing changes canceled changes. it?

ok

i created sample application illustration the question , afterwords checked in db , no users added.

conclusion: objectcontext.savechange it's automatically transaction.

note: believe transactions needed if executing sprocs etc.

c# entity-framework transactions rollback savechanges

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -