Print Page | Close Window

Transaction in DevForce

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2268
Printed Date: 13-Sep-2025 at 7:43pm


Topic: Transaction in DevForce
Posted By: bala
Subject: Transaction in DevForce
Date Posted: 27-Oct-2010 at 11:20am
Hi
I have to use Transaction.
      private void button1_Click(object sender, RoutedEventArgs e)
        {
            PESSOA pessoa = new PESSOA();
            _em.AddEntity(pessoa);
         }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            PESSOA_EMAIL email = new PESSOA_EMAIL();
            _em.AddEntity(email);
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            PESSOA_TELEFONE telefone = new PESSOA_TELEFONE();
            _em.AddEntity(telefone);
       }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
//// _em.saveAsynco()..            
        }
	Above manner i have to use Transaction Commit and rollback
Any Help
PS: I am using oracle as  database.
 
Thanks	
 



Replies:
Posted By: sbelini
Date Posted: 29-Oct-2010 at 11:21am
Hi bala,
 
I'm not sure I understand what you need. Can you clarify?
 
In the meantime, you can find some informations about transactions at
http://drc.ideablade.com/xwiki/bin/view/Documentation/AdvPersist_TransactionalQueries - http://drc.ideablade.com/xwiki/bin/view/Documentation/AdvPersist_TransactionalQueries
and
http://drc.ideablade.com/xwiki/bin/view/Documentation/Saving_Transactions - http://drc.ideablade.com/xwiki/bin/view/Documentation/Saving_Transactions
 
Silvio.


Posted By: bala
Date Posted: 29-Oct-2010 at 11:26am
Hi Sbelini

I went thru  your Example but its not enough to undesrstand me.
I want to save sequentially one by one object if one of object fail due to any reason
I want to roolback it...

for example like power failuare or any techinical  problem..

could you assist me..
thanks


Posted By: sbelini
Date Posted: 29-Oct-2010 at 11:53am

Bala,

By default, saves are transactional, i.e. when you try to save your 3 entities (pessoa, email, telefone), DevForce processes them together as a single unit of work. Either all 3 saves succeed, or they are all rolled back.
 
If I understand, you want to save all 3 entities created (pessoa, email, telefone) in 3 different transactions. If any of them fails, only that particular save is rolled back. If this is the case, you should call Save (or SaveAsync) for each entity (or group of entities you want in a transaction).
 
Please let me know if that's what you are looking for.


Posted By: bala
Date Posted: 29-Oct-2010 at 12:06pm
Hi Silvio

for ex- we have (pessoa,email,telefone) and operation fail on saving telefone
we have to reject changes in pessoa and email too ie rollback in both entities..

I think you got clear view now...


Thanks





Posted By: sbelini
Date Posted: 29-Oct-2010 at 3:00pm
That's the standard behavior if you simply call
 
_em.SaveChangesAsync(...) //if saving telefone fails, pessoa and email will be rolled back
 
Now, if you want to reject the changes in your entity manager, you need to handle the exception accordingly:
 
_em.SaveChangesAsync(savedArgs => {
    if (savedArgs.HasError) {
      // handle exception - reject changes here
    }
  });



Print Page | Close Window