Mapping to SerializableType in Fluent NHibernate
I have an object with a property that I'd like to map as Serializable. NHibernate supports this:
<property name="FeeGenerator" column="FeeGenerator" type="Serializable" />
Is there a way to accomplish this in Fluent NHibernate?
There's an SO question (Map to Serializable in Fluent NHibernate) that would seem to address this, but the only response there doesn't work for me.
If I set
CustomType<NHibernate.Type.SerializableType>();
I get the following Exception:
Could not instantiate IType SerializableType: System.Mis开发者_开发百科singMethodException: No parameterless constructor defined for this object.
I'm surprised that nobody seems to know the answer to this. I did find the answer, and I figured I'd share it.
Basically, you can use the CustomType method to map to any NHibernate type just like you would in XML because there's an overload that takes a string. So the following
CustomType("Serializable");
outputs
<property name="PropertyName" type="Serializable"> ...
I also blogged about this (with some background and more details) over at http://blog.statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx
精彩评论