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

  • Home
  • SEARCH
  • 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 932085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:36:24+00:00 2026-05-15T20:36:24+00:00

I have a custom event listener being added (fluently) to my configuration using: .ExposeConfiguration(c

  • 0

I have a custom event listener being added (fluently) to my configuration using:

.ExposeConfiguration(c => c.SetListener(ListenerType.SaveUpdate, listener))

My listener just captures before a save or update and handles audit fields (CreatedBy, Modified By, etc.)

protected override object PerformSaveOrUpdate(SaveOrUpdateEvent sender)
{
      var entity = sender.Entity as IEditableEntity;

      if (entity != null)
      {
         if (entity.IsNew())
            ProcessEntityBeforeInsert(entity);
         else
            ProcessEntityBeforeUpdate(entity);
      }

      return base.PerformSaveOrUpdate(sender);
}

The ‘entity.IsNew()’ is a method that checks if the Id of the entity is ‘> 0’ and evaluates correctly. However the ‘base.PerformSaveOrUpdate’ is trying performing an insert when it should be an update and is passing null in as the Id (it is mapped as GeneratedBy.Identity()) and I get the following exception:

"Cannot insert the value NULL into column 'Id', table '...'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."
  • 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-15T20:36:25+00:00Added an answer on May 15, 2026 at 8:36 pm

    You should use the PreInsert and PreUpdate methods for that purpose.

    Here’s a full example: http://ayende.com/Blog/archive/2009/04/29/nhibernate-ipreupdateeventlistener-amp-ipreinserteventlistener.aspx

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

Sidebar

Related Questions

I have an event listener for a custom event type. This custom event overrides
I have an application that has created a number of custom event log sources
I have a calendar control derived from DataGridView. A custom item hover event is
I have, for the time being, a custom view with a 9-patch image as
I have a custom event class public class FFTDrawEvent extends Event { public static
I have a java class which fires custom java events. The structure of the
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have custom coded several enterprise applications for mid to large organizations to use
I have custom errors configured in my web.config, but IIS 6.0 is returning the
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For

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.