New Posts New Posts RSS Feed: Transaction
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Transaction

 Post Reply Post Reply
Author
namnl View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Jul-2010
Posts: 6
Post Options Post Options   Quote namnl Quote  Post ReplyReply Direct Link To This Post Topic: Transaction
    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.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 28-Jul-2010 at 5:07pm
Back to Top
namnl View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Jul-2010
Posts: 6
Post Options Post Options   Quote namnl Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
namnl View Drop Down
Newbie
Newbie
Avatar

Joined: 20-Jul-2010
Posts: 6
Post Options Post Options   Quote namnl Quote  Post ReplyReply Direct Link To This Post Posted: 05-Aug-2010 at 12:33am
any idea???
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down