获取PostDeleteEventListener上的主键

时间:2013-06-30 05:14:06

标签: c# nhibernate event-listener

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

1 个答案:

答案 0 :(得分: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)