Das Verwenden von Transactions in LINQ-to-SQL ist total simple:

using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) {
    SomeDatabaseDataContext ctx = new SomeDatabaseDataContext();

    ctx.SomeEntities.InsertOnSubmit(new SomeEntity());
    ctx.SubmitChanges();
    
    ts.Complete();
}

Wichtig ist,das man den Aufruf von ts.Complete() nicht vergisst. Sonst wird ein Rollback auf die Transaktion gemacht!

Für den TransactionScope braucht man eine Referenz auf die System.Transactions.dll.

tl_files/j-schmitz.net/images/WooHooHomer.jpg

Heute morgen habe ich mit 826 Punkten meine MCP Prüfung zum MCTS: Microsoft .NET Framework 3.5, ASP.NET Application Development bestanden!

Nicht so gut habe ich bei "Working with ASP.NET AJAX and Client-Side Scripting" abgeschnitten, dafür habe ich aber bei "Configuring and Deploying Web Applications" und "Targeting Mobile Devices" voll reingehauen.

Nun darf ich auch überall ein tolles MCTS Logo draufpappen:

tl_files/j-schmitz.net/images/mcts.jpg