INotifyPropertyChanged for related field

Posts   
 
    
Posts: 4
Joined: 21-Dec-2011
# Posted on: 21-Dec-2011 08:31:57   

Hello,

I store custom descriptions (culture dependant) for various entities in my database. They all have 1:1 relation with DescriptionEntity which has 1:n relation with CultureDescriptionEntity. I use prefetch to get this DescriptionEntity and one CultureDescriptionEntity (filtered by current application culture). In CommonEntityBase I added property CurrentDescription, which grants access to path: myEntity.Description.CultureDescriptions[0].LocalisedString;

I need to notify CurrentDescription property change when related LocalisedString has been changed. Is it possible to achieve that in LLBLGen entities?

Best regards, Alan

LLBLGen Pro Version 3.1 Adapter template .NET 3.5

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 21-Dec-2011 09:32:20   

IMHO, this is not an LLBLGen Pro question. But rather a .NET question. Am I correct? or am I missing something?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 21-Dec-2011 10:19:41   

Each entity implements INotifyPropertyChanged, so you can bind to the event PropertyChanged of the related entity. This requires some extra code however, as your related entity isn't directly related, but related through a related entity. So you have to add code to that entity (DescriptionEntity, partial class) which overrides OnRelatedEntitySet, and in there bind to the propertychanged event of CultureDescriptionEntity. You might want to add a readonly property to the partial class of DescriptionEntity which returns CultureDescriptions[0]. You can then in DescriptionEntity raise PropertyChanged (by calling OnPropertyChanged(name) for that property so you see the event in the entity related to Description. OnRelatedEntitySet and OnRelatedEntityUnset are your friends here. Be aware that you have to unbind the event as well to avoid memory leaks as .NET doesn't clean up event handlers.

Btw, I wouldn't add the property to the CommonEntityBase, as all entities now have the property, not just the ones which need the property. But it might be all entities need the property so then it's of course the best place to add it.

Frans Bouma | Lead developer LLBLGen Pro