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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:32+00:00 2026-05-13T14:47:32+00:00

Note, this is some ancient NHibernate installation! I have the following NHibernate class: [Serializable]

  • 0

Note, this is some ancient NHibernate installation! I have the following NHibernate class:

[Serializable]
[Class(Table = "SomeEvents")]
public class SomeEvent
{
    [Property(Column="processDate")]
    public DateTime? ProcessDate { get; set; }
}

When trying to update some events like:

using (ISession session = FDK_Hibernate_Manager.OpenSession())
{
    IQuery query = session.CreateQuery(string.Format("FROM {0} e WHERE e.ContractId = :cid", typeof(ContractLeverconditiesEvent)));
    query.SetInt32("cid", contractId);

    foreach(var evnt in query.List().Cast<SomeEvent>())
    {
        evnt.ProcessDate = DateTime.Now;
        session.SaveOrUpdate(evnt);
    }

    session.Flush();
}

I receive the following exception:

Conversion failed when converting datetime from binary/varbinary string.

So I basically guess that NHibernate doesn’t understand my DateTime? yet. My NHibernate install doesn’t have any fancy Nullables.NHibernate.NullableDateTimeType. So anyone has a clue to solve this ancient NHibernate issue?

  • 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-13T14:47:32+00:00Added an answer on May 13, 2026 at 2:47 pm

    I ended up with this (although it can require some work in error-checking and such :-))

    Implement it using [Property(Column = "processDate", TypeType = typeof(NullableDateTime))]

    class NullableDateTime : IUserType
    {
        #region IUserType Members
    
        public new bool Equals(object obj, object obj2)
        {
            return false;
        }
    
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    
        public object DeepCopy(object value)
        {
            return value;
        }
    
        public bool IsMutable
        {
            get { return true; }
        }
    
        public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
        {
            object o = rs[names[0]];
            if (o == DBNull.Value) return new Nullable<DateTime>();
            else
                return new Nullable<DateTime>(((System.Data.SqlTypes.SqlDateTime)o).Value);
        }
    
        public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
        {
            System.Data.Common.DbParameter parameter = (System.Data.Common.DbParameter)cmd.Parameters[index];
            if (value == null)
            {
                parameter.Value = DBNull.Value;
                return;
            }
            else
            {
                parameter.Value = new System.Data.SqlTypes.SqlDateTime((DateTime)value);
            }
        }
    
        public Type ReturnedType
        {
            get { return this.GetType(); }
        }
    
        public NHibernate.SqlTypes.SqlType[] SqlTypes
        {
            get { return new NHibernate.SqlTypes.SqlType[] { new SqlDateTimeType() }; }
        }
    
        #endregion
    }
    
    
    public class SqlDateTimeType : NHibernate.SqlTypes.SqlType
    {
        public SqlDateTimeType() : base(System.Data.DbType.DateTime)
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Note: this is for MS SQL Server) Say you have a table ABC with
Note: This code works now. I have fixed some stupid mistake and I have
Note: I'd appreciate some tag suggestions for this one.. I'd like to provide my
So I have this page that has some basic custom tabs: http://demo.unlockedmanagement.com/users/view/2 * NOTE
I'm loading in some HTML content like this: $('#scores').load('scores.php #scores'); Note that It is
NOTE: This is a followup to my question here. I have a program that
Note: This question has broadened in scope from previous revisions. I have tried to
Note that this question contains some spoilers. A solution for problem #12 states that
**NOTE: This is related to a college assignment. I'm only requesting some guidance in
I have 3 tables (note this may not be the best sql db design)

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.