Welcome to weblogs.com.pk Sign in | Join | Help

Adeel bin Khalid

"When a Man's Education is Finished; He is finished"
WCF and NHibernate: DateTime Null Problem

While sending Nullable DateTime data type you might get an exception: "Cannot convert int32 to datetime" or something like this. This is because WCF doesnt go well with nullable datetime.


Add new methods in the class that uses nullable datatype. Add [OnSerializing] and OnDeserializing] Attributes and their respective methods in your class. In OnSerializing method assigh min datetime to your nullable field. And OnDeserializing method, assign the null value to the datetime field that has min date.

Class testing
  public DateTime myNullableDate? = null;
    internal void OnSerializingMethod(StreamingContext context)
                 myNullableDate = mindate;//change the mindate with right method call

    internal void OnDeserializingMethod(StreamingContext context)
         if(myNullableDate== mindate)
                myNullableDate = null;


Posted: Tuesday, July 14, 2009 7:41 PM by abk
Filed under:


No Comments

Anonymous comments are disabled