title: EF CodeFirst mapping enum with custom value mapping
body: <p>I need to create an application that is compatible with various legacy database systems.
  So, the database exists, but I still want to use code first to be independent from whatever database is used as datastore. For each deployment, I intend to create a "mapping" library containing the correct FluentAPI mappings of the entities to the database.</p>
  
  <p>I'm using EF6.</p>
  
  <p>I don't want code first to alter anything in the database structure automagically, so I use</p>
  
  <pre><code>Database.SetInitializer&lt;mycontext&gt;(null);
  </code></pre>
  
  <p>Now I'm stuck on following issue:</p>
  
  <p>my code defines an enum Gender, which is used as a property in the Person entity</p>
  
  <pre><code>public enum Gender
  {
      M = 1,
      F = 2
  }
  </code></pre>
  
  <p>However, in one of the legacy databases, the values are the other way around. The table "Gender" exists, and the lookup data in that table is ID 1 = female, ID 2 = male.
  The Person table has a "FK Gender ID" column.</p>
  
  <p>How would I configure through Fluent API the mapping of the Gender property of my Person entity, to the Person table in the legacy database table.</p>
  
  <pre><code>modelbuilder.Entity&lt;Person&gt;()
  .Property(c =&gt; c.Gender)
  .HasColumnName("FK Gender ID") //--&gt; and how to "inverse" these values here ?
  </code></pre>
  
  <p>Is this possible with Fluent API, and if not, is there a workaround ?</p>
  
  <p>Thanks.</p>