c# - 在 Fluent NHibernate 中映射到 SerializableType

标签 c# nhibernate fluent-nhibernate

我有一个对象,我想将其映射为可序列化的属性。 NHibernate 支持这个:

<property name="FeeGenerator" column="FeeGenerator" type="Serializable"  />

有没有办法在 Fluent NHibernate 中实现这一点?

有一个 SO 问题 ( Map to Serializable in Fluent NHibernate ) 似乎可以解决这个问题,但那里唯一的回答对我不起作用。

如果我设置

CustomType<NHibernate.Type.SerializableType>();

我得到以下异常:

Could not instantiate IType SerializableType: System.MissingMethodException: No parameterless constructor defined for this object.

最佳答案

我很惊讶似乎没有人知道这个问题的答案。我确实找到了答案,我想我会分享它。

基本上,您可以像在 XML 中一样使用 CustomType 方法映射到任何 NHibernate 类型,因为有一个重载需要一个字符串。所以下面

CustomType("Serializable");

输出

<property name="PropertyName" type="Serializable"> ...

我还在 http://blog.statichippo.com/archive/2010/01/20/mapping-serializable-types-using-fluent-nhibernate.aspx 上写了关于此的博客(有一些背景和更多细节)

关于c# - 在 Fluent NHibernate 中映射到 SerializableType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2097364/

相关文章:

nhibernate - 对 nHibernate 的 ISession 和预加载的关注点分离感到困惑

c# - 无法查询 Yahoo!梦幻体育API

c# - 我的实体模型中应该有外键列吗?

c# - Fluent Nhibernate ManyToMany 集合 - 不保存关联

c# - NHibernate 引用的 C# 标识符中的非 ASCII 字符

c# - 使用 FluentNhibernate 基于列的 Mysql 排名

c# - 如何使用 Fluent NHibernate 映射序列化/反序列化元素列表?

c# - Entity Framework 5 更新对于每个对象/行仅有效一次

c# - 使用 XDocument 读取部分 XML

c# - 在没有完整回发的情况下执行服务器端代码