title: How can I make EF Core database first use Enums?
body: <p>I'm using EF Core with database-first approach using the "Scaffold-DbContext"-command to generate my DbContext / Entities.</p>
  
  <p>How can I instruct Scaffold-DbContext that a certain <strong>field</strong> in a certain <strong>table</strong> should generate code to use an Enum instead of just an int?</p>
  
  <p>This is how you used to do it in regular EF:
  <a href="https://www.devu.com/cs-asp/lesson-69-mapping-enum-types-entity-properties-framework-designer/" rel="noreferrer">https://www.devu.com/cs-asp/lesson-69-mapping-enum-types-entity-properties-framework-designer/</a></p>
  
  <h2>Example</h2>
  
  <p>This enum is already defined in code:</p>
  
  <pre><code>public enum StateEnum {
    Ok = 1,
    Fail = 2
  }
  </code></pre>
  
  <p>This is what Scaffold-DbContext gives me</p>
  
  <pre><code>public partial class Foo
  {
      public int Id { get; set; }
      public int State { get; set; }
  }
  </code></pre>
  
  <p>This is what I want it to create:</p>
  
  <pre><code>public partial class Foo
  {
      public int Id { get; set; }
      public StateEnum State { get; set; }
  }
  </code></pre>