1

如何在 NHibernate 的 PostDeleteEventListener 上获取实体的主键值?(还要考虑复合主键的情况)

4

1 回答 1

1

不确定您是否尝试过某事但失败了……因为传递的PostDeleteEvent对象就是答案:

public void OnPostDelete(PostDeleteEvent @event)
{
    var id = @event.Id;
    var entity = @event.Entity;
    var state = @event.DeletedState;
    ...

如果您看一下父Event构造函数文档PostDeleteEvent : AbstractPostDatabaseOperationEvent

/// <summary> Constructs an event containing the pertinent information. </summary>
/// <param name="source">The session from which the event originated. </param>
/// <param name="entity">The entity to be invloved in the database operation. </param>
/// <param name="id">The entity id to be invloved in the database operation. </param>
/// <param name="persister">The entity's persister. </param>
protected AbstractPostDatabaseOperationEvent(
   IEventSource source
 , object entity
 , object id
 , IEntityPersister persister) 
于 2013-06-30T07:58:32.833 回答