PropertyChanged when One-to-One relation set to null

Posts   
 
    
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 19-Jan-2010 04:55:33   

I have a parent entity Activity which has a 1-1 relation on ActivityBM. When I do the following:

 activity.ActivityBMEntity = new ActivityBMEntity();

the PropertyChanged notification is fired.

Now, when I do this:

 activity.ActivityBMEntity = null;

no PropertyChanged notification is fired.

I have attempted to use OnRelatedEntityUnset, like so:

protected override void OnRelatedEntityUnset(IEntity2 relatedEntity, string fieldName)
        {
            base.OnRelatedEntityUnset(relatedEntity, fieldName);
            this.OnPropertyChanged(fieldName);
        }

but the related object isn't null at this point, so the call doesn't help.

How can I get PropertyChanged notification when a 1-1 related entity is set to null?

Thanks, Josh

-- using the latest templates/drivers/runtime libs (just downloaded) for 2.6

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Jan-2010 10:15:40   

Are these entities in an inheritance hierarchy? If Yes are they of Tye TargetPerHierarchy?

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 19-Jan-2010 10:28:53   

The Activity entity is a super-type (Target Per Entity), though ActivityBM is not part of a hierarchy.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Jan-2010 13:12:56   

tomahawk wrote:

I have a parent entity Activity which has a 1-1 relation on ActivityBM. When I do the following:

 activity.ActivityBMEntity = new ActivityBMEntity();

the PropertyChanged notification is fired.

It can be there are several notifications being raised: the ActivityBMEntity property but also the FK fields in 'activity', as these have been changed (if activity had a reference to another activityBMEntity. )

Now, when I do this:

 activity.ActivityBMEntity = null;

no PropertyChanged notification is fired.

The problem is that the code sees this as a 'dereference' only, and dereferences aren't notified as you'd get twice the notifications when you set a property to a different value. This is indeed a problem. It's in the template, the setter of the property: there it tests for null and if so, it calls the desetupsync method, but that one doesn't notify anything.

I have attempted to use OnRelatedEntityUnset, like so:

protected override void OnRelatedEntityUnset(IEntity2 relatedEntity, string fieldName)
        {
            base.OnRelatedEntityUnset(relatedEntity, fieldName);
            this.OnPropertyChanged(fieldName);
        }

but the related object isn't null at this point, so the call doesn't help.

That's by design, as it passes in the entity which is about to be unset, so not the 'null' value but the entity which is being dereferenced because the reference is set to null.

I'll adjust the template so the propertychanged event is raised properly.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Jan-2010 13:34:27   

Please use the attached template (entityIncludeAdapter.template), which (after generating the code) will fix your problem.

Keep in mind that PropertyChanged isn't some event you should use for BL, it's meant for UI controls which act according to changes of properties.

Frans Bouma | Lead developer LLBLGen Pro
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 20-Jan-2010 02:01:17   

Excellent, that solves it. And yes, this property is bound directly to a WPF UI via a ValueConverter.