title: Mapping a collection of enums with NHibernate
body: <p>Mapping a collection of enums with NHibernate</p>
  
  <p>Specifically, using Attributes for the mappings.</p>
  
  <p>Currently I have this working mapping the collection as type Int32 and NH seems to take care of it, but it's not exactly ideal.</p>
  
  <p>The error I receive is "Unable to determine type" when trying to map the collection as of the type of the enum I am trying to map.</p>
  
  <p>I found a post that said to define a class as</p>
  
  <pre><code>public class CEnumType : EnumStringType {
    public CEnumType() : base(MyEnum) { }
  }
  </code></pre>
  
  <p>and then map the enum as CEnumType, but this gives "CEnumType is not mapped" or something similar.</p>
  
  <p>So has anyone got experience doing this?</p>
  
  <p>So anyway, just a simple reference code snippet to give an example with</p>
  
  <pre><code>    [NHibernate.Mapping.Attributes.Class(Table = "OurClass")]
      public class CClass : CBaseObject
      {
          public enum EAction
          {
              do_action,
              do_other_action
          };
  
          private IList&lt;EAction&gt; m_class_actions = new List&lt;EAction&gt;();
  
          [NHibernate.Mapping.Attributes.Bag(0, Table = "ClassActions", Cascade="all", Fetch = CollectionFetchMode.Select, Lazy = false)]
          [NHibernate.Mapping.Attributes.Key(1, Column = "Class_ID")]
          [NHibernate.Mapping.Attributes.Element(2, Column = "EAction", Type = "Int32")]
          public virtual IList&lt;EAction&gt; Actions
          {
              get { return m_class_actions; }
              set { m_class_actions = value;}
          }
  }
  </code></pre>
  
  <p>So, anyone got the correct attributes for me to map this collection of enums as actual enums? It would be really nice if they were stored in the db as strings instead of ints too but it's not completely necessary.</p>