I have a one-to-many relationship within my class model.
Example:
A single role can have many permissions attached to it. so have two table one from the role and one for the permissions for each role.
Now i have a role class which in turn has a permission list as a member of that class. When i need to do an update, i instantiate a transactionscope object, and do an update for the role. After that is done and with the transactionscope still open, i open another transactionscope for each permission in the list and close it immediately after the update has been done.
The update for the role works just fine
But, now the problem is that when it tries to instantiate a transactionscope for the first permission on the list it trows an error saying:
Error: Time-out interval must be less than 2^32-2. Parameter name: dueTm
Ok, i found a solution.
Scenario:
I have two base classes for my Business Layer,
BaseBLLandBaseListBLL. Each of these classes provided a method that calls an astract method that must be implemented in you concrete class. These classes started aTransactionScopebefore handing off to the abstract class to perform tasks like update or insert.Note: After the BaseListBLL starts off a
TransactionScopeit calls the method in theBaseBLLthat also starts it’s own transaction. This is because, we’ll be inserting or updating a list of classes derived from theBaseBLLwhich all together are contained in a class derived fromBaseListBLL.Now for example if we are to update a role in the roles table only one transaction would be started. But now the complexity comes when we have a role object having another class that derives directly from the
BaseListBLL.A transaction would be started for the list first and another for each
BaseBLLobject in the list to do all the insert or update.So now, after the first insert, the error:
is thrown.
What i did was
For the list class, i set the
TranscationScopeobject this way:and for the other class
The conclusion i have derived is that the error is being thrown because i was using the same transaction created by the
BaseBLLderived class from the list. I had to suppress the ambient transaction when it was time to do an update of the list of items.I hope this helps someone else.