Adapter Databinding using dot notation

Posts   
 
    
johnfattal
User
Posts: 6
Joined: 14-Feb-2007
# Posted on: 01-Mar-2007 11:48:32   

I'm having trouble binding to a property of an object within my parent object using adapter and prefetch path. Schema has a 1-m relationship 'Account' to 'Contact'. Each Account should have one contact defined by it's foreign key, and I am retrieving this successfully using the prefetch path:

i.e.

PrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.AccountEntity);
prefetchPath.Add(AccountEntity.PrefetchPathContact);

I am binding my IEntityCollection2 '_model' to a bindingsource once the data has been retrieved, and if I cast an item in the collection to an AccountEntity I can see that the 'Contact' object has been retrieved.


        /// <summary>
        /// Bind Controls to the DataSource
        /// </summary>
        public void BindControls()
        {
            this._accountBindingSource.DataSource = _model;

            this._accountNameTextBox.DataBindings.Add("Text", _accountBindingSource, "AccountName");
            this._accountNumberTextBox.DataBindings.Add("Text", _accountBindingSource, "AccountNumber");
            this._accountDetailsMCodeTextBox.DataBindings.Add("Text", _accountBindingSource, "MCode");
            this._accountDetailsNotifyCheckBox.DataBindings.Add("Text", _accountBindingSource, "Notify");
            this._accountDetailsPinTextBox.DataBindings.Add("Text", _accountBindingSource, "Pin");

            this._accountDetailsContactTelephoneNumberTextBox.DataBindings.Add("Text", _accountBindingSource,"Contact.LastName");
            BindTreeView();

            this._dataBound = true;
        }

However, binding fails when binding to 'Contact.LastName' with the following message. 'DataMember property 'Contact' cannot be found on the DataSource.'

Looks to be related to the Browsable attribute? confused

Any Ideas?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Mar-2007 16:21:07   

Add a 'field mapped onto related field' field to Account which you map on the Contact.LastName field (say you name it "ContactLastName"). Then when you fetch the Account collection, specify a prefetch path to also fetch the related Contact. This should populate the ContactLastName field, which should be used in databinding.

johnfattal
User
Posts: 6
Joined: 14-Feb-2007
# Posted on: 01-Mar-2007 16:32:39   

Will do, however the same seems to apply to EntityBase2 Fields. For Example I would like to bind the Enabled property of my Apply and Cancel buttons to the IsDirty flag exposed in the AccountEntity object from EntityBase2.

Is this then a different issue?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 02-Mar-2007 03:05:07   

I believe that would be a different issue. Have you tried this and it didn't work?

johnfattal
User
Posts: 6
Joined: 14-Feb-2007
# Posted on: 02-Mar-2007 10:33:02   

Yes. The IsDirty Property on EntityBase2 is marked as [Browsable(false)]. At the moment I'm using a workaround by adding a browsable property to the Entity class that just passes up the IsDirty property - but perhaps there is a correct way of doing this?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 02-Mar-2007 12:51:27   

johnfattal wrote:

Yes. The IsDirty Property on EntityBase2 is marked as [Browsable(false)]. At the moment I'm using a workaround by adding a browsable property to the Entity class that just passes up the IsDirty property - but perhaps there is a correct way of doing this?

Thanks

It's marked with Browsable(false) to avoid having it turn up in grids automatically when columns are autodiscovered. The workaround is indeed to add a custom property which mimics isdirty and returns the value instead.

Frans Bouma | Lead developer LLBLGen Pro