title: How to map an enum in a one-to-many relationship with fluent API in Entity Framework?
body: <p>My question is simple, and related to this other one (<a href="https://stackoverflow.com/questions/17422806/how-to-map-an-enum-in-a-one-to-many-relationship-with-nhibernate">How to map an enum in a one-to-many relationship with NHibernate?</a>) although here I'm specifically asking about the fluent API for Entity Framework.</p>
  
  <p>Let's say (the same example) I have these two entities in my model, one reference type (User) and another an enum (Roles).</p>
  
  <pre><code>class User { int id; IList&lt;Roles&gt; Roles; }
  
  enum Roles { Worker, Manager, Director }
  </code></pre>
  
  <p>Or in this representation for clarity...</p>
  
  <pre><code>[users]   [ roles ] 
  +-----+   +-------+
  | id  |   |user_id|
  +-----+   +-------+
            | value | &lt;- [Represented by the enum]
            +-------+
  </code></pre>
  
  <p>Now I want to use fluent API to map this to my database in Entity Framework, but if I try...</p>
  
  <pre><code> HasMany(x =&gt; x.Roles)
     .Cascade.All()
     .Table("UserRoles")
     .Element("RolesEnum");
  </code></pre>
  
  <p>... it will fail, as <code>HasMany()</code> is not reference type.</p>
  
  <p>Is there a way of doing this in fluent API that does not involve changing my business model from an enum to a class?</p>