I'm using NHibernate 3.1. I have a user type that represents a System.Drawing.Image
. It works perfectly fine until I change the mapping of an image property to enable lazy loading for the property.
At a certain point, NHibernate decides to update an entity that has the image property. What happens is that in the following method of the user type, value
has a value that is not an actual Image
:
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
...
}
Obviously this is the case because the image property was not accessed so the lazy loading mechanism wasn't triggered. What I don't get here is that the value is not开发者_如何学C null
but a quick watch in the debugger doesn't give me any details about the instance other than that it is an 'object'. Could it be some sort of proxy-ish instance?
So now I'm looking for a way to effectively have NHibernate refrain from updating the property when it hasn't changed. Simply returning from the method right away doesn't work because then an exception is thrown, stating that the value for the property is missing.
You should be able to force NHibernate to refrain from updating the property by declaring the property as a one-to-one (or many-to-one, depending on your scenario) with cascade="none",
rather than as a "direct" property of the entity.
精彩评论