如何在NHibernate的PostDeleteEventListener上获取实体的主键值? (还考虑了复合主键的情况)
答案 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)