SaveMulti with validator

Posts   
 
    
Lomegah
User
Posts: 19
Joined: 21-Apr-2005
# Posted on: 12-May-2005 17:30:30   

Everytime I try to use SaveMulti with a collection of objects, on which I coded a validator class, this is the problem that i get:

It looks like the validate statement ( which is a dao.GetScalar ) uses its own transaction, while the update/insert commands use another transation. When this problem occurs, the second update/insert command bumps on a locked table, and I get a timeout expired message. I cannot find the transaction that u/i command uses while I'm in the validator class. How can I avoid this error ?

In the meantime, I have stopped using Collections.SaveMulti, and I manually code every Collection.entity.save. That way, the problem does not occur, but I would prefer that the function is automated using SaveMulti, rather than having to do it manually each time with Collection.entity.save.

Thank you for your assistance simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-May-2005 18:22:28   

Every entity which is saved using SaveMulti() is saved in the transaction the collection is in. You can grab teh transaction from the entity passed into the IEntityValidator implementation: entity.Transaction.

Though I see that dao.GetScalar doesn't have an overload which accepts a transaction indeed. I'll file it as a bug so it will get fixed with the proper overload.

Frans Bouma | Lead developer LLBLGen Pro
Lomegah
User
Posts: 19
Joined: 21-Apr-2005
# Posted on: 12-May-2005 19:43:28   

I noticed that dao.GetScalar has this parameter ( containingTransaction As ITransaction ). Is there something to do with that parameter to solve my problem ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-May-2005 20:34:03   

Lomegah wrote:

I noticed that dao.GetScalar has this parameter ( containingTransaction As ITransaction ). Is there something to do with that parameter to solve my problem ?

flushed I completely overlooked that parameter! I checked the method, didn't saw a transaction, so it has to be overloaded, but of course you can use that parameter.

What you should do is pass the entity.Transaction value as the value for containingTransaction. Then the GetScalar call will be called using the connection of the transaction, and deadlocks are not happening.

Frans Bouma | Lead developer LLBLGen Pro
Lomegah
User
Posts: 19
Joined: 21-Apr-2005
# Posted on: 16-May-2005 15:33:38   

Great !! It works, thank you ! smile