English 中文(简体)
How do I create different sessions for different windows in a desktop application with ActiveRecord?
原标题:

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?

最佳回答

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.

问题回答

暂无回答




相关问题
Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

Problem find joined table in rails

I have model represent association rule (Body => Head) def Item has_many :heads has_many :bodies ... end def Rule has_many :heads has_many :bodies ... end def Body belongs_to :item belongs_to :rule ...

FreeTDS Bad token from the server (SQL Server)

Today we had a lot more activity than normal between our Ruby on Rails application and our remote legacy SQL Server 2005 database, and we started getting the error below intermittently. What is is? ...

Castle ActiveRecord: one-to-one

While playing around with one-to-one associations in castle activerecord I stumbled upon the following problem: I m trying to model a one-to-one relationship (user-userprofile in this case). I ...

Sending email updates: model or observer?

I have an Event model, which stores an event feed for each user. I also need to email the updates to users which have enabled email notifications in their profile. From an architectural point of view,...

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

热门标签