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.