title: How do I map a C# int to a SqlServer tinyint using Entity Framework Code First?
body: <p>I have a POCO model class and an existing DB table, <strong>neither of which I am able to change</strong> I am using Entity Framework 6 and the Fluent API.</p>
  
  <p>The model class has a CountryId of 'int'. However, in the database table, the CtryId is a 'tinyint'.</p>
  
  <p>I tried to set the type using </p>
  
  <pre><code>modelBuilder.Entity&lt;Event&gt;().Property(e =&gt; e.CountryId).HasColumnName("CtryId").HasColumnType("tinyint");
  </code></pre>
  
  <p>in the OnModelCreating method but get the following error:</p>
  
  <pre><code>error 2019: Member Mapping specified is not valid. The type 'Edm.Int32[Nullable=False,DefaultValue=]' of member 'CountryId' in type 'RA.Data.Event' is not compatible with 'SqlServer.tinyint[Nullable=False,DefaultValue=]' of member 'CtryId' in type 'CodeFirstDatabaseSchema.Event'.
  </code></pre>
  
  <p>How do I map a C# int to a SqlServer tinyint using Entity Framework Code First?</p>