Search code examples
nhibernatefluent-nhibernatenhibernate-mappinglegacy

how do you translate a space value in a database field to a null in .NET with Fluent NHibernate?


I am working with a legacy database that stores "blank" values as a single space. Is there a way with Fluent NHibernate, either by way of a convention or mapping override, that I can translate this "blank" value as a .NET null? (I know that I will need to save nulls to this database as a single space still but I will use an save event listener for that).


Solution

  • You should use a custom implementation of IUserType for this, not a listener. Here's one example of many examples available on the web. James Gregory wrote a good article on how to implement IUserTypes using a Fluent NHibernate conventions.