I use DevExpress' XPO ORM, but I suspect that this applies to many other ORMs and this happens to me all of the time and it's starting to get annoying.
The situation is:
- 1 form with a UnitOfWork used to populate user controls etc. with data from the db. (eg. a user settings form)
- a dialog window with a UnitOfWork used to populate user controls. (eg. a permissions screen)
The resolutions that I can think of aren't ideal. Keep in mind that I can't copy objects across sessions/units of work in XPO (as far as I can tell).
I don't want to just create the the persistent 开发者_运维知识库objects in the dialog and commit them with the dialog's unit of work, because then the user can't cancel out of the form without making changes (unless I went back to the DB and deleted the object persisted in the dialog)
Forcing all of the dialogs in the software to take a reference to a unit of work in the constructor smells terrible.
Having to re-create objects in the form that were created in the dialog smells terrible as well.
what else can I do?
This is a late answer, but may help others: The solution to your problem is to use a Nested Units of Work.
精彩评论