Open Closed

Repository.DeleteAsync() does not trigger Deleting-EventHandler #8155

alexanderpilhar created

8.0.0, Angular, .NET Core

I need to set a relation between two entities of type A and B to null before deleting entity of type A. I thought I could do that easily with predefined events but it turns out the deleting event handler does not get triggered (also, see EntityDeletingEventData does not fire on deleting user #1460).

Right now, I call the deleting event handler manually using the event bus before deleting the entity itself:

public async Task DeleteAsync(int id)
    await EventBus.TriggerAsync(new EntityDeletingEventData<A>(new A { Id = id }));

    await _aRepository.DeleteAsync(id);

This works as expected but I guess it is not how it is supposed to be done!? Any ideas why the deleting event handler doesn't get triggered properly? Am i missunderstanding something?

2 Answer(s)
  • 1
    demirmusa created

    It fires but after save changes but before committing a transaction.


  • 0
    alexanderpilhar created

    I see, thanks @demirmusa!

    I thought I could use the deleting event handler in order to avoid a foreign-key constraint when deleting entity of type A. But it doesn't work like that. I guess, I'll better be using a custom event handler instead of the deleting event handler.