TechTalk Genome v4.2

Context.DeleteObject Event

Raised before a persistent object is deleted in this Context using Delete method.

public event ObjectEventHandler DeleteObject;




Signals that the Context is about to delete sender by calling Delete or DeleteCurrent. This event allows the subscriber to perform cleanup tasks before sender would get inaccessible in the given Context. The event is raised before the operation would take place thus allowing to access all properties and methods of sender. If sender was unchanged before the call to Delete then ChangeObject event is raised by the same Context before the DeleteObject subscribers would get notified.

Events raised by the Context can be captured from different areas of interest. The developer may choose to capture a certain event originating from a certain Context by subscribing to one of the Context events using the standard .NET event mechanism. This allows for multiple queued event processors and dynamic strategies in handling events. The order in which subscribers are notified is nondeterministic and hence no subscriber should perform operations with side-effects that would affect the execution of other subscribers or that assumes a certain execution order. This way of processing Context events is similar to handling events raised by ADO.NET DataTable.

The developer might optionally choose to process Context events on persistent objects directly. In this case the class implementing persistency should be inherited from the corresponding callback interface. Each callback interface defines one method to implement with a similar signature as the corresponding event delegate. When the Context raises an event for a persistent object it executes the callback method whenever the object implements the appropriate callback interface. This practically ensures that the object is always subscribed to all events of any Context that it is interested in regardless of how the Context itself is configured by the caller.

The Context that raises the event will automatically become the active Context in the calling thread for the duration of the call. This ensures that any unbound proxies used in the event handlers are resolved from the relevant Context. When the events have been successfully processed, the context stack of the calling thread is restored to its previous state.


class CascadingDeleteChild : Persistent
    public abstract CascadingDeleteParent Parent { get; set; }

class CascadingDeleteParent : Persistent, IDeleteCallback
    public Set Children
        [return: ElementType(typeof(CascadingDeleteChild))]
            return Domain.Extent(typeof(CascadingDeleteChild))["Parent=={0}", this];
    void IDeleteCallback.OnDelete()
        foreach(CascadingDeleteChild child in Children.ToArray())


Namespace: TechTalk.Genome

Assembly: TechTalk.Genome (in TechTalk.Genome.dll)


Editions: Professional, Evaluation, Express

See Also

Context Class | TechTalk.Genome Namespace | IDeleteCallback | Delete | LoadObject | ChangeObject