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
|
Hello, sorry if this has been asked before, I just couldn't find a good way to express it simply so here's a question: When I make a OneToManyAssociation between for example Order and Product, I would like to have some code running both when setting Product.Order = Order and when calling Order.Products.Add(Product). In my mind those are the same operation, but a quick test confirms that if I put some validation code in the setter for Product.Order, it's not executed when i do Order.Products.Add(). Am I doing a mistake in assuming that adding something to one part of the association is the same as adding it to the other? If so, any advice how to handle this situation is much appreciated. Thanks! /Andreas |
|
|
No, you are correct that it doesn't matter which end you set up the association from. However, the wiring-up of the other end does not go through your property setter: it operates directly on the underlying field. |
|
|
So would a good solution to my problem be to attach the code to the AddingNew event of the EntityCollection Order.Products? Then will it run whenever I set Product.Order? |
|
|
Sort of. You can't use the AddingNew event: that is specific to databound scenarios (in particular the AddNew method). But listening for the ListChanged event should work. Be sure to check for ListChangedType.ItemAdded because you will also get ItemChanged and other notifications through this event. |
|