Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.MissingMethodException: No parameterless constructor defined for this object.
like image 981
hackerhasid Avatar asked Jan 19 '10 21:01

hackerhasid


1 Answers

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

like image 127
hackerhasid Avatar answered Oct 17 '22 20:10

hackerhasid