Fluent NHibernate 中映射到 SerializedType
我有一个带有属性的对象,我想将其映射为可序列化。 NHibernate 支持这一点:
<property name="FeeGenerator" column="FeeGenerator" type="Serializable" />
Is有一种方法可以在 Fluent NHibernate 中实现这一点吗?
有一个SO问题(Map to Serialized in Fluent NHibernate)似乎解决这个问题,但唯一的回应对我不起作用。
如果我设置
CustomType<NHibernate.Type.SerializableType>();
我会得到以下异常:
Could not instantiate IType SerializableType: System.MissingMethodException: No parameterless constructor defined for this object.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令我惊讶的是,似乎没有人知道这个问题的答案。我确实找到了答案,并且我想我会分享它。
基本上,您可以使用 CustomType 方法映射到任何 NHibernate 类型,就像在 XML 中一样,因为有一个需要字符串的重载。 以下
输出
因此,我还在 http://blog.statichippo.com/archive/2010/01/20/mapping-serialized-types-using- Fluent-nhibernate.aspx
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
outputs
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