omar wrote:
Greetings,
I used to have my entities share an adapter (to span transactions across entities) so that the entity that created the adapter is the one that gets to COMMIT the adapter.
After learning about the UOW functionality I see how it helps in shortening the transaction.
My question, If an entity wants to do some data access work (using UOW) with an adapter passed on to it while another entity wants to use the same adapter for some other data-acces work (without UOW);
1- will committing the adapter out-of the UOW commit the UOW (If I issue Adapter.commit, would that implicitly commit any UOW using that adapter)
The UnitOfWork simply executes actions on the adapter passed in. If the adapter passed in has already a transaction started, no transaction is started, the current one is used, otherwise a new one is started. If you haven't specified to autocommit itself (in the Commit call of the UnitOfWork), the UnitOfWork won't commit the transaction, otherwise it will.
If you halfway through the actions of the UnitOfWork commit teh transaction, it will then run into problems at the end when committing plus the actions starting from that point aren't done inside a transaction. So it's not wise to commit the transaction then, but after the UnitofWork's Commit() call returns (or let the UnitOfWork.Commit() call do the commit of the transaction automatically
2- would committing the UOW itself commit all the transactions using the UOW's adapter even those not inside the UOW?
It will commit the transaction of the adapter it uses. So any call to that adapter after the commit will thus not use a live transaction, as that's then committed. Any call to the adapter when a transaction is active is done inside that transaction.
3- Does serializing a UOW object result in serializing the Entities and EntityCollections inside it (like the Context object)?
Yes. This has been optimized in 1.0.2005.1, where it first calculates the entities it has to work on (also recursive saves), so it creates 2 queues for insert and update actions, and serializes these, which gives much smaller sizes in data.