Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 463495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:10:50+00:00 2026-05-12T23:10:50+00:00

I’m implementing a custom EventListener to save auditing information in NHibernate. I’m currently extending

  • 0

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?

[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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:10:50+00:00Added an answer on May 12, 2026 at 11:10 pm

    I’m not sure how you can accomplish this with ActiveRecord but it has to do with the mechanism in which NHibernate persists parent/child relationships.

    Saving the child cascade prior to saving the parent in NHibernate is by design depending on which end of the relationship is marked as “inverse=true” and the child needs to have a “not-null=true” attribute on the element (which determines which end owns the relationship). This will make it so the Child is managing the state of the relationship.

    Then you can simply save the child, and the parent will be updated with the appropriate information. This will generate one INSERT statement, instead of an INSERT AND UPDATE that you are probably seeing now. Not sure if this solves your problem, but I believe the problem you are having is around this behavior. You can read more at this link:

    https://www.hibernate.org/hib_docs/nhibernate/html/example-parentchild.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.