1

我有一个用户类,它有一个属性事件,它有很多会话。基本上,用户注册一个有很多会话时间的事件。

用户可以注册一个活动,但会议时间纯粹是提供信息。

但是当我使用 NH 将用户写入数据库时​​,它也会更新会话时间。我如何防止这种情况发生,因为我知道在创建/更新事件时仍然需要插入/更新会话时间。

4

1 回答 1

0

This might not totally apply to your question, but I've had issues where I wanted to conditionally cascade deletes based on certain business rules.

A lot of the times, you can handle this in your persistence logic. I had a case where I went with NHibernate Event Listeners.

public class ConditionalDeleter: IPostDeleteEventListener
    {
        public void OnPostDelete(PostDeleteEvent @event)
        {
            var foo = @event.Entity as Foo;
            if (foo != null)
            {
                if (foo.ShouldDeleteBar)
                {
                    ISession session = @event.Session.GetSession(EntityMode.Poco);
                    session.Delete(foo.Bar);

                    session.Flush(); 
                }
            }
        }
    }
于 2011-04-22T19:00:42.673 回答