Accessing the CurrentContext in an XDataServer Event

To access the current context in a service implementation we have the TXDATAOperationContext object which make life easy.

If I have a TXDataServer Event, let's say OnModifying. where should I get the current context from, so I can access teh ObjectManager for example?

In this case I have an object that is called from the event, along the lines of:

procedure TServerContainer.XDataServerEntityModifying(Sender: TObject; Args: TEntityModifyingArgs);
  lMyObject: IMyObject;
  lMyObject := TMyObject.Create(Args.Entity, Args);

Would TXDATAOperationContext be available within the object as it is within a service method?



1 Like

I'm really starting to love XData :smiley:

1 Like

one more question. If I use the Object Manager from the current context to update a secondary entity and the main entity fails to update for some reason, would the second entity get rolled back within the same transaction?

The transactions are per connection. If you use the Object Manager from the context, then all operations done with it will be of course be done under the same connection. Thus yes, all operations will be rolled back together.

1 Like