Mike Nichols - Son of Nun Technology

NHibernate Generic Class Mapping

I needed to implement a component that uses generic parameters. Documentation is sketchy on NHibernate so thot I'd jot it here. I *stole* an IRange implementation from someone and needed to use it for a date range within a class.

    <component name="DateTimeRange" class="Cei.eMerge.Common.Range`1[System.DateTime], Cei.eMerge.Common" access="field.camelcase-underscore" >

      <property name="Start" access="field.camelcase">

        <column name="StartDate" not-null="true" />

      </property>

      <property name="End" access="field.camelcase">

        <column name="EndDate" not-null="true"/>

      </property>

    </component>

Note the `[genericTypeParameter] syntax. Here's how we map it. Be sure you have a default constructor! The exceptions thrown by NOT having a default constructor are riddles at best.