title: Entity Framework Core 2.0 mapping enum to tinyint in SQL Server throws exception on query
body: <p>I get the following exception when I try to map an <code>enum</code> to <code>smallint</code> in <code>OnModelCreating</code>:</p>
  
  <blockquote>
    <p>InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.Int32'.</p>
  </blockquote>
  
  <p>I want to do this because in SQL Server an <code>int</code> is 4 bytes while a <code>tinyint</code> is 1 byte.</p>
  
  <p>Relevant code:
  Entity:</p>
  
  <pre><code>namespace SOMapping.Data
  {
      public class Tag
      {
          public int Id { get; set; }
  
          public TagType TagType { get; set; }
      }
  
      public enum TagType
      {
          Foo,
          Bar
      }
  }
  </code></pre>
  
  <p>DbContext:</p>
  
  <pre><code>using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  
  namespace SOMapping.Data
  {
      public class ApplicationDbContext : IdentityDbContext
      {
          public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
              : base(options)
          {
          }
  
          public DbSet&lt;Tag&gt; Tags { get; set; }
  
          protected override void OnModelCreating(ModelBuilder builder)
          {
              builder.Entity&lt;Tag&gt;().Property(m =&gt; m.TagType).HasColumnType("smallint");
  
              base.OnModelCreating(builder);
          }
      }
  }
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>using System.Linq;
  using Microsoft.AspNetCore.Mvc;
  using SOMapping.Data;
  
  namespace SOMapping.Controllers
  {
      public class HomeController : Controller
      {
          private ApplicationDbContext _applicationDbContext;
  
          public HomeController(ApplicationDbContext applicationDbContext)
          {
              _applicationDbContext = applicationDbContext;
          }
  
          public IActionResult Index()
          {
              var tags = _applicationDbContext.Tags.ToArray();
              return View();
          }
      }
  }
  </code></pre>
  
  <p>Is there a way I can make this work so that I don't have to use 4 times as much space with all my <code>enum</code>s?</p>