I'm implementing a custom EventListener to save auditing information
in NHibernate.

I'm currently extending DefaultSaveOrUpdateEventListener, overriding
PerformSaveOrUpdate, going through the properties of each entity and
saving them elsewhere.

This works with simple properties, but fails when cascade-saving a one-
to-many relationship.

If I take the following entities:

    [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<Child> Children { get; set; }
    }

And then save a parent with a child:

    ActiveRecordMediator<Parent>.Save(new Parent
    {
        Children = new List<Child>
        {
            new Child()
        }
    });

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.

How can I get the value that will actually be persisted to the
database in this case?

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=.


Reply via email to