How to have NHibernate persist a String.Empty property value as NULL
        Posted  
        
            by Todd
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Todd
        
        
        
        Published on 2010-04-07T12:57:15Z
        Indexed on 
            2010/04/07
            18:03 UTC
        
        
        Read the original article
        Hit count: 257
        
I have a fairly simple class that I want to save to SQL Server via NHibernate (w/ Fluent mappings). The class is made up mostly of optional string fields.
My problem is I default the class fields to string.empty to avoid NullRefExceptions and when NHibernate saves the row to the database each column contains an empty string instead of null.
Question: Is there a way for me to get NHibernate to automatically save null when the string property is an empty string? Or do I need to litter my code with if (string.empty) checks?
© Stack Overflow or respective owner