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. C#
  4. Undo changes to context when using EntityFramework 4.0/4.1

Undo changes to context when using EntityFramework 4.0/4.1

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    MaWeRic
    wrote on last edited by
    #1

    I have Invoice entity wich I change and then add InvoiceRows and then I want to cancel the whole operation. What is the easiest way of doing this? I can use Context.refresh() to get a fresh copy of my Entity but is this really the way to do it? //h

    D A 2 Replies Last reply
    0
    • M MaWeRic

      I have Invoice entity wich I change and then add InvoiceRows and then I want to cancel the whole operation. What is the easiest way of doing this? I can use Context.refresh() to get a fresh copy of my Entity but is this really the way to do it? //h

      D Offline
      D Offline
      dasblinkenlight
      wrote on last edited by
      #2

      I would use Context.Refresh(RefreshMode.StoreWins, obj) as my "Plan B". My "Plan A" would be keeping changes outside of Context until they are ready to be committed, and then apply and commit them in an atomic operation. This requires more work as you need to track the state of newly added entities, but I think it is worth it, because the approach is cleaner overall.

      1 Reply Last reply
      0
      • M MaWeRic

        I have Invoice entity wich I change and then add InvoiceRows and then I want to cancel the whole operation. What is the easiest way of doing this? I can use Context.refresh() to get a fresh copy of my Entity but is this really the way to do it? //h

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        Transaction. I've not worked with them with Entity Framework myself, but that seems like what you want.

        Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

        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