views:

72

answers:

2

I am having some issues with binding to objects retrieved from NHibernate using lazy loading. I have read some on the issue and am confused on what I need to do to fix things here.

As I understand it the issue has to do with the way NHibernate handles the proxies for things that haven't been loaded yet. Has someone implemented NHibernate using lazy loading and INotifyPropertyChanged?

Right now INotifyPropertyChanged works if I disable lazy-loading, but otherwise no UI elements get updated if they are bound to things which are lazily loaded. I am already a bit in over my head with all of this and the proxy implementation is even more foreign to me so I am not exactly what it is I even need here. :) I am hoping that there is some reasonably simple solution.

A: 

Hello,

If you are sure you have been proxy your domain using NH Interceptor than everything should work fine. Except if you made mistake on session management, because interception didn't work outside session scope. Did you micro managed your session per method call of your repository?

Actually the best practice for non web base application is managing session per form, maybe you have read this, that article explain about managing session per form but the solution is a bit dirty, because session distributed in the presenter.

The most cleanest session management I ever seen is uNhAddins with Castle Adapter where you only care of configuration the rest you program your repository and service naturally. Here is a technical reference : part 1, part 2, part 3, part 4.

My favorite example is this one, But in context of WPF you should take a look at this one.

Hope that help.

ktutnik
some link are broken, because they used mercurial now
ktutnik
A: 

I got this figured out. I needed to follow the example here: http://www.progware.org/Blog/post/NHibernate-PropertyChanged-event-and-WPF.aspx

The step that seemed to be missing was that I needed a ProxyFactoryFactory that returned the data binding factory created by this example: http://ayende.com/Blog/archive/2009/08/07/nhibernate-amp-inotifypropertychanged.aspx

Hopefully this is helpful to someone.

Justin