views:

76

answers:

1

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?

+1  A: 

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.

MZywitza
Thanks for the answer. If I don't use a SessionScope, will it actually create a separate instance of the data item to edit? The reason I ask is because another issue I'm running into is if they both use the same instance (even if I don't Save()) the INotifyPropertyChanged messages are going to the main window - which I don't want. So working with a discrete copy sounds best if that's possible?
Abby Fichtner
THANK YOU!! I am just about to head to the CodeMash conference for the week, but I will DEFINITELY try this when I get back. Quick question - will this allow lazy loading (e.g., via data binding - so calls that occurred outside the new ConversationalScope(conversation))?
Abby Fichtner
Yes, I even pointed that out in a comment in that test. I enhanced it today, I think it will be feature complete by the end of this week.
MZywitza
Just downloaded from trunk and built, going to see if I can figure this out - is there an email address I could contact you at? Or could you drop me an email: haxrchick at gmail? Thanks!
Abby Fichtner
You're welcome at [email protected]
MZywitza