Databinding nested properties

This will be a common problem when using NHibernate. You want to show something on datagrid like EntityA.EntityB.EntityC.property1, but you can’t. Somebody said it’s impossible from MicroSoft forum.

A guy from Oslo got a solution by extending standard BindingSource component, which is too complex to me. The more important thing is, don’t put too many code in UI. Also, I couldn’t event open his original post on codeproject.

When I tried to expose those nested properties in parent Entity Object, I couldn’t figure out the NullReferenceExpection. Too many magics happen in NH’s ORM process.

Mabsterrama’s front-end re-formatting idea works great so far, even it’s also a UI layer solution.

Michal Talaga gave a explanation why datagrid doesn’t have this problem when using SqlDataSource but in objectDataSource. His solution is almost the one I want, BO/Domain layer work around, kind of ‘object view’. The real objectView project is based on MS’s Enterprise Library. (What’s that?)

Actually, expose the child/nested properties isn’t that hard. Only one line of code.

        public virtual string Location   {    get { return site.CurrentName; } }

But this againsts OO. I wish dotNet35+ will fix this weakness soon.

 

Here is another solution in UI layer: coding in InitializeRow event.

Advertisements

One thought on “Databinding nested properties

  1. Hi there,
    it seems you are seriously looking to find out a proper solution for this problem. (I have the same problem too)
    and thanks you this post which was very nice.
    I you found something more efficient, please let me know.
    thanks in advance.

    Siavashgm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s