This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am extending an entity and my goal is to recalculate a property and fire a change notification on that new property when another property changes. In my example, lets say you have a purchase order, and there are purchase order details. When the purchase order detail "TitleId" or Title reference is changed, I want to hook into that and set my property called LastPricePaid. To me it seems hackish to hook into the PropertyChanged Event of my own entity and look for these two properties to be changed. Is there a better way without wrapping the object in a ViewModel? Thanks, Joe Feser |
|
|
In general, you can override the OnPropertyChanged virtual method instead of hooking the event. However, what you're talking about is specific business logic associated with the Title property, which probably belongs in the Title and TitleId setters. If you're hand-coding classes, you can obviously just write this in your property setters. If you're using the designer, you have a bit of extra work to do first because you need to tell the designer, "Don't generate the getter-setter logic for these properties -- I'll take care of this." To do this: 1. Select the property in the designer. 2. Change the Generation setting to FieldOnly. 3. In the partial class, write your custom get/set logic. (As a starting point, you may want to take a copy of the generated code before doing step 2.) E.g. public int TitleId { Note that you do need to do the Title association. Although changes to Title will cascade to TitleId, LightSpeed will do this by updating the _titleId field directly, so any TitleId setter logic will NOT be called if someone sets Title. |
|