我目前正在使用NHibernate v5.2,这是我的IPreDeleteEventListener
的实现,但是我仍然看到运行代码后它没有更新数据库。
有什么办法吗?
预先感谢
public class SoftDeleteEventListener : IPreDeleteEventListener
{
public bool OnPreDelete(PreDeleteEvent @event)
{
var softDeletable = @event.Entity as ISoftDeletable;
if (softDeletable != null)
{
EntityEntry entry = @event.Session.GetSessionImplementation().PersistenceContext
.GetEntry(@event.Entity);
entry.Status = Status.Loaded;
// Thats the property i need to change
softDeletable.IsDeleted = true;
Object id = @event.Persister.GetIdentifier(@event.Entity);
Object[] fields = @event.Persister.GetPropertyValues(@event.Entity);
Object version = @event.Persister.GetVersion(@event.Entity);
@event.Persister.Update(id, fields, new Int32[1], false, fields, version,
@event.Entity, null, @event.Session.GetSessionImplementation());
return true;
}
return false;
}
public Task<bool> OnPreDeleteAsync(PreDeleteEvent @event,
CancellationToken cancellationToken)
{
throw new System.NotImplementedException();
}
}