hac*_*sid 8 c# nhibernate fluent-nhibernate
我有一个具有属性的对象,我想将其映射为Serializable.NHibernate支持这个:
<property name="FeeGenerator" column="FeeGenerator" type="Serializable" />
Run Code Online (Sandbox Code Playgroud)
有没有办法在Fluent NHibernate中实现这一目标?
有一个问题(在Fluent NHibernate中映射到Serializable)似乎可以解决这个问题,但是那里唯一的反应并不适用于我.
如果我订
CustomType<NHibernate.Type.SerializableType>();
Run Code Online (Sandbox Code Playgroud)
我得到以下例外:
Could not instantiate IType SerializableType: System.MissingMethodException: No parameterless constructor defined for this object.
Run Code Online (Sandbox Code Playgroud)
我很惊讶没有人知道答案.我确实找到了答案,我想我会分享它.
基本上,您可以使用CustomType方法映射到任何NHibernate类型,就像在XML中一样,因为有一个带有字符串的重载.所以以下
CustomType("Serializable");
Run Code Online (Sandbox Code Playgroud)
输出
<property name="PropertyName" type="Serializable"> ...
Run Code Online (Sandbox Code Playgroud)
我还在http://blog.statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx上发表了关于此的博文(有一些背景和更多细节).
| 归档时间: |
|
| 查看次数: |
1200 次 |
| 最近记录: |