在NHibernate级联中软删除

时间:2009-12-07 10:31:28

标签: nhibernate soft-delete

我尝试通过实现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

但它不会从一对多,可能对多的关系中软删除实体。有人有解决方案吗?

0 个答案:

没有答案