Blog Stats
  • Posts - 62
  • Articles - 1
  • Comments - 31
  • Trackbacks - 64

 

NHibernate Class Mapping With Generic Parameters

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.


Feedback

No comments posted yet.


Post a comment





 

Please add 1 and 3 and type the answer here:

 

 

Copyright © Mike Nichols