【发布时间】:2011-03-25 08:04:32
【问题描述】:
我一直在尝试使用 NHibernate (2.1.2.4000) 和 NHibernate.Mapping.Attributes (1.2.1.4000) 将 IDictionary 映射到数据库,但没有成功。我在网上找到了一些博客提到可以映射到属性([1][2]),但我似乎无法让它工作,因为我不断收到以下错误:
映射泛型集合 FormsEntity.Attributes 时出错:应有 1 个泛型参数,但属性类型有 2 个
属性属性如下所示:
[Map(2, Name = "Attributes", Cascade = CascadeStyle.All)]
[Key(3, Column = "FormsEntityID")]
[Index(4, Column = "Name", Type = "string")]
[CompositeElement(5, ClassType=typeof(HtmlAttribute))]
public virtual IDictionary<string, HtmlAttribute> Attributes
{
get { return _attributes; }
set { _attributes = value; }
}
这又会生成以下 .hbm 文件:
<hibernate-mapping auto-import="false" xmlns="urn:nhibernate-mapping-2.2">
<joined-subclass name="FormsEntity, Entities" extends="BaseEntity, Entities"
table="CMS_FormsEntity ">
<key column="Id" />
<property name="Title" />
<property name="Description">
<column name="description" sql-type="nvarchar(MAX)" />
</property>
<property name="IsTemplate" />
<map name="Attributes" cascade="all">
<key column="FormsEntityID" />
<index column="Name" type="string" />
<composite-element class="HtmlAttribute, Entities" />
</map>
</joined-subclass>
</hibernate-mapping>
使用的资源:
- [1] How to map to a Generic IDictionary
- [2] NHibernate Mapping (the section of mapping a complex value type)
我读过的其他主题
【问题讨论】:
标签: nhibernate nhibernate-mapping asp.net-4.0