Monday 26 November 2007

Databinding NHibernate

Had a few problems data-binding lists returned from NHibernate (queries or collections) where the first object in the list was a proxy. We previously 'fixed' this by clearing the session prior to running the query. This then caused further problems as objects were detached and the lazy-lists threw exceptions.

The solution we came to is based on : This posting by Ayende

A TypeDescriptor was created for EntityBase (all our objects returned from NHibernate inherit from EntityBase) which was registered with the web-site in the Global.asax Application_StartUp.