title: Map a field to an enum in EntityFramework 5 Code First
body: <p>So, I have a class as follows:</p>
  
  <pre><code>public class Message {
  
          public enum MessageType {
              Text = 0,
              Audio = 1,
              Image = 2
          }
  
          public int Uid { get; set; }
          public MessageType Type { get; set; }
          public String Text { get; set; }
  
  }
  </code></pre>
  
  <p>As you can see, the Type field is an enum. My mapping to match up the data to this class is defined like this:</p>
  
  <pre><code>public class MessagesMap : EntityTypeConfiguration&lt;Message&gt; {
  
      public MessagesMap() {
  
          // Primary Key
          this.HasKey(t =&gt; t.Uid);
  
          // Properties
          this.Property(t =&gt; t.Text)
              .HasMaxLength(1000);
  
          // Table &amp; Column Mappings
          this.ToTable("wc_messages");
          this.Property(t =&gt; t.Uid).HasColumnName("UID");
          this.Property(t =&gt; t.Type).HasColumnName("Type");
          this.Property(t =&gt; t.Text).HasColumnName("Text");
  
      }
  }
  </code></pre>
  
  <p>But when I run the code, I get the following error:</p>
  
  <blockquote>
    <p>The property 'Type' is not a declared property on type 'Message'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.</p>
  </blockquote>
  
  <p>I understand I'm getting the error as the Type property is not a primitive, but an enum. If I understand correctly, though, EF5 supports enums (and I'm targeting the .NET 4.5 framework) so I assume I'm missing something in my mapping that's not explaining how to convert to the enum, but I'm at a loss as to what that is. If I change the field back to an int it all works fine, it's only when the field type is the enum that I get the error.</p>
  
  <p>What am I missing? Thanks in advance.</p>