开发者

Mapping to SerializableType in Fluent NHibernate

开发者 https://www.devze.com 2022-12-17 02:01 出处:网络
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\"/>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号