Q about Transactions

Posts   
 
    
Anderskj1
User
Posts: 33
Joined: 11-Jan-2005
# Posted on: 20-Jan-2005 19:27:29   

Hi

I have a serval inserts in different tabels wich i want in the same transaction, therefor I create a Transaction to add my entities to (This is selfServicing)

But Let say I have this T1 and T2 is related

...

T1Entity t1 = new T1Entity() t1.text = 1;

T2Entity t1 = new T2Entity() t2.text = 2; t2.T1 = t1;

trasaction.Add(t2);

t2.Save(true);

....

Is it ok not to add the t1 to the transaction when using recursive save?

Thanks in reagards Anders

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Jan-2005 10:20:42   

You don't have to add the related entities to the transaction, that's right. In fact, you don't have to create a transaction if you just save a single graph recursively, as a transaction is created for you behind the scenes. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Anderskj1
User
Posts: 33
Joined: 11-Jan-2005
# Posted on: 21-Jan-2005 16:08:35   

Perfect with nested autotransaction. But im using these nested transaction + some other "unrelated" insert wich has to fail too in case of error.

Just a little subquestion. Is it a problem if some entities somhow is added twice to a transaction?

Thanks Anders

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Jan-2005 16:31:38   

Yes, if you add an entity twice you'll get an exception. You can check if an entity is already in a transaction by checking entity.ParticipatesInTransaction , which is then true.

Frans Bouma | Lead developer LLBLGen Pro