In DO3.9, there was an OnReferenced event that was raised when an entity was referenced by another entity. For example, if I have Order and OrderLineItem, when OrderLineItem.Order is set to some Order, Order.OnReferencing is raised.

I have implemented soft deletes using a field called Active. I would like to prevent any deactivated records from being referenced by other entities.

What is the most efficient way of implementing this?

asked Jan 26 '11 at 01:52

ara's gravatar image

ara
395858791


One Answer:

Hello Ara,

There is a way to achieve the goal, here is how:

First, subscribe to the Session.SystemEvents.NotifyFieldValueSettingAttempt event when Session is opened. The best place to do this is to subscribe to Domain.SessionOpen event, where you will get access to every newly opened Session instance.

Second, handle NotifyFieldValueSettingAttempt properly: check whether e.Field is a reference field and e.Value is Entity and it is "marked as removed". If so, throw the appropriate exception.

Hope that helps.

answered Jan 26 '11 at 05:53

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

edited Jan 26 '11 at 05:54

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×9

Asked: Jan 26 '11 at 01:52

Seen: 1,985 times

Last updated: Jan 26 '11 at 05:54

powered by OSQA