Вы можете добавить PreInsertEventListener и переопределить функцию, чтобы выполнить необходимое преобразование пустой строки в значение NULL.
Это можно сделать следующим образом:
public class NhibernateEventListeners : IPreInsertEventListener
{
public bool OnPreInsert(PreInsertEvent nHibernateEvent)
{
var entityBeingInserted = nHibernateEvent.Entity;
if (entityBeingInserted == null)
return false;
if (property.PropertyType==typeof(string))
{
//use reflection to set the property value to null
}
return false;
}
}
, и при настройке сеанса убедитесь, что вы добавили следующее в свою конфигурацию
_config.ExposeConfiguration(
config => config.SetListener(ListenerType.PreInsert, new NhibernateEventListeners()));
Надеюсь, что этоэто то, что вы ищете и вам помогает.