Question

I'm building a desktop application with Castle ActiveRecord and want to be able to do the equivalent of 1 nHibernate session per window form. Any ideas on how can I do this with Active Record?

Specifically, I have a main window that allows you to browse the data (read-only) and then you can open separate forms to edit the data.

Each time a form is opened, I want to create a new session, get a copy of the data to edit (so it can be changed without yet impacting the data in the main window). I then want to be able to manipulate that copy via data binding. And finally, either commit the changes (if the user chooses to Save) or roll them back (if the user chooses to cancel).

Any ideas?

Was it helpful?

Solution

If you don't need lazy loading, don't use a SessionScope. You can simply databind and call entity.Save() on Save. Since your objects are detached without a SessionScope, you don't have to do anything on cancellation of the form.

If you need lazy loading, then this won't work with plain ActiveRecord yet. A ConversationalScope that allows using CpBT (in your case Conversation per Form Instance) is planned, but not available yet.

One possibility is to try Rhino Commons which has a unit-of-work-implementation for ActiveRecord. This could allow what you want with current AR, but I didn't use it for about 2 years.

Edit: A basic CpBT implementation is now available from trunk. Check-out and build with nant. See this link for how to use it: https://svn.castleproject.org/svn/castle/ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Conversation/ConversationScenarioTest.cs It is not production ready yet, but I'd love feedback on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top