Event when a related entity is set

Posts   
 
    
Posts: 3
Joined: 18-Jan-2007
# Posted on: 18-Jan-2007 16:47:52   

I saw that when you set a related entity property (1:1 relation) to an entity, you don't raise a PropertyChanged event as you do for simple property (string, int, ...). Is there a particular reason why you don't implement it ? Ex : IncidentEntity incident = new IncidentEntity(); incident.Vehicle = new VehicleEntity(); => I'm interesting to be inform when the Vehicle property has changed.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jan-2007 17:02:33   

PropertyChanged is an event meant for bound UI controls, i.o.w. a databinding event

The following events exist in LLBLGen Pro 2.0: OnRelatedEntitySet and OnRelatedEntityUnset

Please refer to: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6828

Posts: 3
Joined: 18-Jan-2007
# Posted on: 19-Jan-2007 17:21:13   

Yes I saw this thread but this force me to inherit from my entity (IncidentEntity). I think an event is more convenient and don't really understand the real reason you don't raise this event.

Why don't you generate by default in the template an VehicleChanged event (according to my example) ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 20-Jan-2007 00:58:35   

Sylvain wrote:

Yes I saw this thread but this force me to inherit from my entity (IncidentEntity). I think an event is more convenient and don't really understand the real reason you don't raise this event.

Why don't you generate by default in the template an VehicleChanged event (according to my example) ?

VehicleChanged as in: 'Vehicle' is the related entity? Nice suggestion. I'll look into that. One can't have both _field_Changed and PropertyChanged events in one class unfortunately, as winforms databinding will then fail, so either one of them has to be chosen.

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 21-Jan-2007 11:12:52   

Otis wrote:

Sylvain wrote:

Yes I saw this thread but this force me to inherit from my entity (IncidentEntity). I think an event is more convenient and don't really understand the real reason you don't raise this event.

Why don't you generate by default in the template an VehicleChanged event (according to my example) ?

VehicleChanged as in: 'Vehicle' is the related entity? Nice suggestion. I'll look into that. One can't have both _field_Changed and PropertyChanged events in one class unfortunately, as winforms databinding will then fail, so either one of them has to be chosen.

Although mainly used for data binding fields, I see the new-style PropertyChanged event as representing _any _property change. The name of the property changed is passed in the PropertyName property of PropertyChangedEventArgs (or null or string.Empty to indicate all fields may have changed) so there is no confusion over what has changed - "Vehicle" in this case - easy to check against and type safe if you compare against xxxFields.Vehicle.Name.

Cheers Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 22-Jan-2007 11:55:42   

Clever thinking, I think that's indeed a much better approach. Thanks for the insight simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 3
Joined: 18-Jan-2007
# Posted on: 22-Jan-2007 17:53:21   

Thanks for your quick answer. smile