NHibernate:级联删除的 c# 操作

NHibernate: c# action on cascade deletion

我已经通过级联删除实现了一对多的代码映射。我有与子实体相关联的文件。我想在子级联删除时自动删除文件。 如何实施?

我发现 NHibernate 在配置级别支持监听器。它并不完美,但聊胜于无。简化示例:

var deleteListener = new DeleteListener();
_configuration.SetListener(ListenerType.Delete, deleteListener);

class DeleteListener : DefaultDeleteEventListener {
    public override void OnDelete(DeleteEvent e, ISet<object> transientEntities) {
        MyEntity entity = e.Entity as MyEntity;
        if (entity != null) {
            // code for file deletion
        }
        base.OnDelete(e, transientEntities);
    }
}