title: Mapping a long data property to int in database
body: <p>In all of the examples that I've seen use <code>int32</code>s as the IDs. That's not always practical in production environments. Several of our databases have identity IDs that are in the realm of <code>int64</code>s, so our practice is to always use <code>long</code> for our ID properties. However, SQL Server has higher max values for the <code>int</code> column type.</p>
  
  <p>I'm doing our first proof of concept with Entity Framework version 6. With the <code>long ID</code>, it's unable to map the object to the database.</p>
  
  <p>I'm using Fluent API for all of my mapping. Right now, it looks like this for the ID:</p>
  
  <pre><code>Property(s =&gt; s.ID).HasColumnName("spcID");
  </code></pre>
  
  <p>If I add a <code>.HasColumnType("int")</code> to the end of the above, it gives me the following error:</p>
  
  <blockquote>
    <p>Schema specified is not valid. Errors:  (7,12) : error 2019: Member
    Mapping specified is not valid. The type
    'Edm.Int64[Nullable=False,DefaultValue=]' of member 'ID' in type
    'EFConnection.Space' is not compatible with
    'SqlServer.int[Nullable=False,DefaultValue=,StoreGeneratedPattern=Identity]'
    of member 'spcID' in type 'CodeFirstDatabaseSchema.Space'.</p>
  </blockquote>
  
  <p>How do you map the datatype for these to a long variable in .NET?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Right now, I have a simple Integration Test set up to make sure that I can connect:</p>
  
  <pre><code>[TestMethod]
  public void TestMethod1() {
      using (var context = new Context()) {
          Assert.IsTrue(context.Spaces.Any());
          Assert.IsTrue(context.Spaces.First().IsActive);
      }
  }
  </code></pre>
  
  <p>Without the <code>.HasColumnType("int")</code>, the first Assert passes, but I get an <code>InvalidOperationException</code> on the second:</p>
  
  <blockquote>
    <p>The 'ID' property on 'Space' could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Int64'.</p>
  </blockquote>