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
|
In our code we have to take action whenever entities are created (not loaded, only created from code). For standard entities we can write our own constructor, so there is a place where we can act. But through associations are handled by Lightspeed - through entities are created with default, parameterless constructor. We can override it, but: |
|
|
You can actually do option (2) already using the underlying EntityCollection of the ThroughAssociation. Consider two entities, Contribution and Tag, with a many-to-many association with a ContributionTag through entity. Then Contribution has a ContributionTags EntityCollection which underlies the Tags ThroughAssociation. You can subscribe to this collection's EntityAdded event and the event data will contain the newly created through entity. var c = _unitOfWork.FindById<Contribution>(1); The EntityAdded event does not fire for through entities being materialised from the database, but from your description you're only interested in newly created entities anyway. One caveat: in my sample code, accessing c.ContributionTags to subscribe to the EntityAdded event will cause c.ContributionTags to be loaded from the database (because the property getter calls the Get method). This is probably not what you want if you want to allow your through associations to be lazy loaded. In reality you would subscribe through the private _contributionTags field, typically in the Contribution constructor (accessing the field does not load the collection because it does not call the Get method). |
|
|
Thank you for your help. Your solution works as expected. |
|