Print Page | Close Window

Transaction

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2017
Printed Date: 16-Apr-2025 at 12:41pm


Topic: Transaction
Posted By: namnl
Subject: Transaction
Date Posted: 27-Jul-2010 at 8:09pm
Hello IB support team, please help me how to apply transaction when insert or update entity, so i can rollback whenever it has problem.
Thanks.



Replies:
Posted By: davidklitzke
Date Posted: 28-Jul-2010 at 5:07pm

Browse to here:

http://www.ideablade.com:8989/xwiki/bin/view/Documentation/SavingBusinessObjects#HSavesandTransactionManagement - http://www.ideablade.com:8989/xwiki/bin/view/Documentation/SavingBusinessObjects#HSavesandTransactionManagement

 



Posted By: namnl
Date Posted: 01-Aug-2010 at 8:07pm
The built-in transaction of DevForce seems commit after we do "SaveChanges". Can we force it commit after the last time we do "SaveChanges". For example,

//insert parent item
ParentItem pi = new ParentItem();
...//set parent item property
pi.EntityAspect.AddToManager();
mrg.SaveChanges();
//get parentOI
int parentOI= pi.oi;
//insert children item
ChildrenItem ci = new ChildrenItem();
...//set children item property
ci.EntityAspect.AddToManager();
mrg.SaveChanges();

I got problem when inserting children item, but ParentItem still inserted. How can i resolve this?


Posted By: namnl
Date Posted: 05-Aug-2010 at 12:33am
any idea???


Posted By: kimj
Date Posted: 05-Aug-2010 at 2:55pm
You're correct that every SaveChanges call is transactional.  I'm not sure I understand the problem here, however.  
 
For one, you don't have to call SaveChanges for every entity, but can instead save the chosen (or all) entities when ready.  So here, you can create the parent and all children and then call SaveChanges() or SaveChanges(IEnumerable).
 
Next, if you do want to save the parent, and then later save the children, I don't understand what error you're getting, or is your question theoretical?  If theoretical, DevForce does not directly support multiple SaveChanges calls within a single transaction.  If your application is 2-tier you can open a TransactionScope around your SaveChanges calls and everything within will be saved or rolled back together.  If your application is n-tier this is much harder.
 
In general, instead of looking to transactions you should really be treating the parent and its children as an object graph and saving that graph with a single SaveChanges call.
 
 



Print Page | Close Window