NHibernate 级联中的软删除

发布于 2024-08-13 22:45:36 字数 1138 浏览 8 评论 0原文

我尝试通过实现 DeleteEvent Listener

公共类 MyDeleteEventListener : DefaultDeleteEventListener

{

protected override void DeleteEntity(IEventSource session, object entity, 

    EntityEntry entityEntry, bool isCascadeDeleteEnabled, 

    IEntityPersister persister, ISet transientEntities)

{

    if (entity is ISoftDeletable)

    {

        var e = (ISoftDeletable)entity;

        e.IsDeleted = true;



        CascadeBeforeDelete(session, persister, entity, entityEntry, transientEntities);

        CascadeAfterDelete(session, persister, entity, transientEntities);

    }

    else

    {

        base.DeleteEntity(session, entity, entityEntry, isCascadeDeleteEnabled,

                          persister, transientEntities);

    }

}

}

(https://web.archive.org/web/20090209010820/http://blogs.hibernatingrhinos.com/nhibernate/archive/ 2008/04/08/soft-deletes.aspx

但它不会软删除一对多、多对多关系中的实体。有人有解决办法吗?

I try to make a soft delete by implementing the DeleteEvent Listener

public class MyDeleteEventListener : DefaultDeleteEventListener

{

protected override void DeleteEntity(IEventSource session, object entity, 

    EntityEntry entityEntry, bool isCascadeDeleteEnabled, 

    IEntityPersister persister, ISet transientEntities)

{

    if (entity is ISoftDeletable)

    {

        var e = (ISoftDeletable)entity;

        e.IsDeleted = true;



        CascadeBeforeDelete(session, persister, entity, entityEntry, transientEntities);

        CascadeAfterDelete(session, persister, entity, transientEntities);

    }

    else

    {

        base.DeleteEntity(session, entity, entityEntry, isCascadeDeleteEnabled,

                          persister, transientEntities);

    }

}

}

(https://web.archive.org/web/20090209010820/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/08/soft-deletes.aspx)

But it does not soft-delete the entities from one-to-many, may-to-many relationships. Has someone a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文