Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate EventListeners - getting the value of a property of the entity being saved
    primarykey
    data
    text
    <p>I'm implementing a custom EventListener to save auditing information in NHibernate.</p> <p>I'm currently extending DefaultSaveOrUpdateEventListener, overriding PerformSaveOrUpdate, going through the properties of each entity and saving them elsewhere.</p> <p>This works with simple properties, but fails when cascade-saving a one-to-many relationship.</p> <p>If I take the following entities:</p> <pre><code>[ActiveRecord] public class Child { [PrimaryKey(PrimaryKeyType.GuidComb)] public Guid Id { get; set; } [BelongsTo] public Parent Parent { get; set; } } [ActiveRecord] public class Parent { [PrimaryKey(PrimaryKeyType.GuidComb)] public Guid Id { get; set; } [HasMany(Cascade = ManyRelationCascadeEnum.SaveUpdate)] public IList&lt;Child&gt; Children { get; set; } } </code></pre> <p>And then save a parent with a child:</p> <pre><code>ActiveRecordMediator&lt;Parent&gt;.Save(new Parent { Children = new List&lt;Child&gt; { new Child() } }); </code></pre> <p>The child will get the correct parent assigned to it when its persisted to the database but the 'Parent' property of the child is null when my EventListener is called.</p> <p>How can I get the value that will actually be persisted to the database in this case?</p> <p>[EDIT] I've recently been looking at getting this to work by hooking the cascade and seeing what else was being saved at the time, but that seems horribly unreliable and I'd much prefer to get the data out of NHibernate so I know it's consistent with the database.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload