locked
Can I use Astoria SaveChanges for transactions? RRS feed

  • Question

  • Can I delete multiple objects in the same context and call SaveChanges once at the end to 'commit' all the deletions?
    If I don't call SaveChanges and delete the context, are the deletions 'rolled back'?

    Also, I would like to delete a hierarchy of objects recursively, but found that I could not tell if an object was already marked for deletion. It would be nice to expose that flag as read-only on the entity and be able to use it in a query.
    Thursday, January 1, 2009 6:02 PM

All replies

  • It appears that SaveChanges does indeed work this way.

    Objects marked for deletion can be found like this:

    var queryDeletedEntities = from e in context.Entities  
        where (e.State & System.Data.Services.Client.EntityStates.Deleted) == System.Data.Services.Client.EntityStates.Deleted  
        select new { e.Entity };  
     
    Friday, January 2, 2009 1:06 PM
  • Hello Ozzy

    as the writer above the ado.net framework does that.

    Regards

    Daniel Portella
    http://undocnet.blogspot.com
    Thursday, January 8, 2009 1:42 PM
  • Just to add a bit.  If you don't save and dispose the context, there is nothing to rollback.  The changes are just objects that never getted saved and are disposed as long as your not holding references to them elsewhere.  This is one good reason to use the unit-of-work pattern and try not to pass contexts and entities around in your app, but keep them local in scope and work. 
    Monday, January 12, 2009 3:05 PM