Mapping a collection of Enums with NHibernate


Just came across a situation where I needed to have a collection of enum values mapped to an IList and to have it supported by NHibernate. It took me a little bit to find the proper approach and get NHibernate to play nicely. So as a reference for anyone else running into this you can find some information at this posting here

Here is a snippet of the bag at hand:

<bag name=”companyRoleList” access=”field” lazy=”false” cascade=”none” table=”CompanyRole” >
    <key column=”CompanyID” />
    <element column=”RoleID” type=”MyCompany.Domain.Lookups.CompanyRoleType, MyCompany.Domain.Lookups” />
</bag>
This is from the blog post on the NHibernate forum. The trick here is to have the full namespace/assembly qualification in the type attribute that points to the Enum you are using as a collection. This is needed even if you have the namespace=, assembly= at the hibernate-mapping element. That stumped for a little while. Hopefully this helps someone else out!
I must admit