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

Related Questions

I am looking to knock off a quickie rails app that will allow two
I've got two ListBox'es that are databound to the same BindingList. The issue is
I have two issues both related to (I believe) my SQL Server setup. I
I have inherited a middle tier system with some multi-Threading issues. Two different threads,
Two questions: Can someone point me to unbiased data that compares .NET performance to
Two Questions: Will I get different sequences of numbers for every seed I put
I have a set of operations that are very expensive but are all pretty
SVN and CVS are two very different systems that aim to address the same
I'm not the first to have these issues, and will list some reference posts
We have two distinct agile teams, each working on separate, but related, applications. Each

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.