1

I've been trying to map a IDictionary to a database using NHibernate (2.1.2.4000) and NHibernate.Mapping.Attributes (1.2.1.4000) with no success. I found a few blogs online that mention that it's possible to map to an attribute([1][2]), but I can't seem to get it to work because I keep getting the following error:

Error mapping generic collection FormsEntity.Attributes: expected 1 generic parameters, but the property type has 2

Attribute property looks like the following:

[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; }
}

Which in turn generates the following .hbm file:

<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>

Resources used:

Other threads I've read

Community
  • 1
  • 1
creatio
  • 815
  • 9
  • 16

1 Answers1

0

You need to specify how to map properties on your composite element:

    <map name="Attributes" cascade="all">
          <key column="FormsEntityID" />
          <index column="Name" type="string" />
          <composite-element class="HtmlAttribute, Entities">
               <property name="Name" />
               <property name="Value" />
          </composite-element>
    </map>

Substituting whatever your property names are.

Vadim
  • 17,897
  • 4
  • 38
  • 62