Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. LINQ and Transactions? How to rollback appropriately?

LINQ and Transactions? How to rollback appropriately?

Scheduled Pinned Locked Moved LINQ
csharpdatabasesql-serverlinqsysadmin
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CDHatLib
    wrote on last edited by
    #1

    I have some new stuff that I'm writing for work and thought "Oh let's see if we can't show the value of LINQ with this project!" Well I'm having some problems and those problems majorly are as far as transactions (at least for now). Essentially the specs are something like this Start transaction if (Do some stuff for Table 1 != OK) { Rollback and leave } if (Do some stuff for Table 2 != OK) { RollBack and leave } if (Do some stuff for Table 3 != OK) { Rollback and leave } if (Do some stuff for Table n != OK) { Rollback and leave } End transaction (Commit) Now I dont' see anything as far as the documentation that insertonsubmit (formerly known as add) actually does anything that would cause SQL Server to return an error of some sort that you would if you called it with an Insert clause. And I for sure don't see anything that denotes itself as a rollback. My understanding if things is that the SubmitChanges is akin to calling Commit. And if that is so then you can't roll back after a commit. So given the above scenario I don't see how you can get around having to do a lot of work you need to do to set up for an insert (or delete or such) in Table N, when Table N-1 will have an error that will mean a rollback will need to be done. I hope that makes sense (at least a bit) and I'll be glad to clarify as much as possible. Christopher

    H 1 Reply Last reply
    0
    • C CDHatLib

      I have some new stuff that I'm writing for work and thought "Oh let's see if we can't show the value of LINQ with this project!" Well I'm having some problems and those problems majorly are as far as transactions (at least for now). Essentially the specs are something like this Start transaction if (Do some stuff for Table 1 != OK) { Rollback and leave } if (Do some stuff for Table 2 != OK) { RollBack and leave } if (Do some stuff for Table 3 != OK) { Rollback and leave } if (Do some stuff for Table n != OK) { Rollback and leave } End transaction (Commit) Now I dont' see anything as far as the documentation that insertonsubmit (formerly known as add) actually does anything that would cause SQL Server to return an error of some sort that you would if you called it with an Insert clause. And I for sure don't see anything that denotes itself as a rollback. My understanding if things is that the SubmitChanges is akin to calling Commit. And if that is so then you can't roll back after a commit. So given the above scenario I don't see how you can get around having to do a lot of work you need to do to set up for an insert (or delete or such) in Table N, when Table N-1 will have an error that will mean a rollback will need to be done. I hope that makes sense (at least a bit) and I'll be glad to clarify as much as possible. Christopher

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      The SubmitChanges call in LINQ to SQL does create an implicit transaction to ensure that all changes are made, or if any fails, the whole thing fails. However, there are times when you might want to specifically have several SubmitChanges calls which need to be wrapped in an explicit transaction. This is simple enough, as the DataContext has a Transaction property and you can also use wider transactions - see this video: Mike Taulty's screencast on transactions[^]

      'Howard

      J 1 Reply Last reply
      0
      • H Howard Richards

        The SubmitChanges call in LINQ to SQL does create an implicit transaction to ensure that all changes are made, or if any fails, the whole thing fails. However, there are times when you might want to specifically have several SubmitChanges calls which need to be wrapped in an explicit transaction. This is simple enough, as the DataContext has a Transaction property and you can also use wider transactions - see this video: Mike Taulty's screencast on transactions[^]

        'Howard

        J Offline
        J Offline
        jatin sabarmati
        wrote on last edited by
        #3

        nice find , thanx

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups