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 152913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:42:29+00:00 2026-05-11T09:42:29+00:00

Two issues that will likely be immediately obvious, but I’ve spent too long already

  • 0

Two issues that will likely be immediately obvious, but I’ve spent too long already tracking them down:

  1. I’ve set up an AuditInterceptor in order to do automatic auditing on entities that implement my IAuditable interface which is used as follows:

    public class AuditInterceptor : EmptyInterceptor { public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) { var auditable = entity as IAuditable;

        if (auditable == null)         return false;      var now = DateTime.Now;     auditable.CreateDate = now;     auditable.ModifiedDate = now;      return true; }  public override bool OnFlushDirty(object entity, object id, object[] currentState,     object[] previousState, string[] propertyNames, IType[] types) {     var auditable = entity as IAuditable;      if (auditable == null)         return false;      auditable.ModifiedDate = DateTime.Now;      return true; } 

    }

The two fields are both not nullable in the database, POCO, and mapping file. However, on Save, while the interceptor is being called (can step through it and see the applicable fields being set to DateTime.Now), there’s still an SqlDateTime exception being thrown:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

I’ve seen this before where there’s been a mismatch somewhere (mapping file, database, POCO) where the DateTime is specified null in some and not in others. However, I’ve checked and it’s all good on that front. I can manually set the values before SaveOrUpdate(entity) and it inserts/saves without problems. Without manually setting them, It’s acting as if the interceptor is being missed altogether (even though I know it’s not) and the two DateTime properties are never set (and therefore are treated as DateTime.MinValue: 01/01/0001…) and therefore out of range. But when stepping through, the values are properly set to DateTime.Now.

What is happening? For what it’s worth, I had actually set up an event listener previously as well and it resulted in the same issue.

  1. Now for a dumb question that must have been answered out there somewhere, but I can’t find it: As part of dealing with the above issue, I quickly checked to see whether making DateTime nullable throughout, but I know one of the breaking changes with NHibernate 2.* is that the NHibernate.Nullables are no longer supported. Therefore, what do you use in your mapping file to map the nullable DateTime? type? For i.e.:

Understandably doesn’t work:

<property name='CreateDate' column='CreateDate' type='DateTime?' not-null='false' /> 

And no longer supported:

<property name='ModifiedDate' column='ModifiedDate' type='Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate' not-null='false'/> 

Any pointers would be much appreciated!

  • 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. 2026-05-11T09:42:29+00:00Added an answer on May 11, 2026 at 9:42 am

    This explains it:

    if (!(entity is IAuditable))     return false;  DateTime now = DateTime.Now; state[Array.IndexOf(propertyNames, 'CreateDate')] = now; state[Array.IndexOf(propertyNames, 'ModifiedDate')] = now;  return true; 

    But still wondering about the 2.* way to declare DateTime? in NHibernate mapping files.

    [Update] Asked it in another question and got the answer: https://stackoverflow.com/questions/593236/nhibernate-2-mapping-files-how-to-define-nullable-datetime-type-datetime

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

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The jQuery dialog will take the user's focus ( you… May 11, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer Brad Abrams posted an e-mail from Brian Harry written during… May 11, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer Select a.ID, b.Name, a.Place from StorageItem a inner join Storage… May 11, 2026 at 6:10 pm

Related Questions

Two issues that will likely be immediately obvious, but I've spent too long already
Given a list of urls, I would like to check that each url: Returns
SVN and CVS are two very different systems that aim to address the same
I have a bunch of scripts - some in perl and some in bash
There are two projects in one VS solution: client(wpf app) and а wcf service

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.