Friday, January 8, 2010

NHibernate: Mapping a Generic List of Enum

I recently ran into a case where I wanted to have a collection of an enumeration on one of my domain classes.


public class MyDomainClass
public List<MyRoleEnum> Roles { get; set; }

But how is do we map something like this in an xml mapping? A quick google didn't turn up the answer, so I played around a bit and found the following works as desired.

<bag name="Roles" table="MyDomainClass2Role">    
<key column="MyDomainClassId" />
<element column="Role" type="MyRoleEnum" />

To confirm this usage I checked the documentation at Turns out the <element /> tag was designed for value type bags anyway.

No comments: