title: Entering keys manually with Entity Framework
body: <p>I'm trying to use Entity Framework code first for a simple database project and I run into a problem I simply cannot figure out. </p>
  
  <p>I noticed EF was setting the ID for my tables automatically increasing by 1 each time, completely ignoring the value I entered manually for that field. After some searching it is my understanding that the right way to disable this behavior is doing:</p>
  
  <pre><code>modelBuilder.Entity&lt;Event&gt;().Property(e =&gt; e.EventID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
  </code></pre>
  
  <p>However now I'm just getting this error and I have no idea why:</p>
  
  <blockquote>
    <p>Unhandled Exception:
    System.Data.Entity.Infrastructure.DbUpdateException: An error
    occurred while updating the entries. See the inner exception for
    details. ---</p>
    
    <blockquote>
      <p>System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. --->
      System.Data.SqlClient.SqlException: Cannot insert explicit value for
      identity column in table 'Events' when IDENTITY_INSERT is set to OFF.</p>
    </blockquote>
  </blockquote>
  
  <p>If it's helpful, here is the POCO class in question:</p>
  
  <pre><code>public class Event
  {
      [Key, Required]
      public int EventID { get; set; }
  
      public string EventType { get; set; } //TODO: Event Type Table later on
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
  
      public virtual ICollection&lt;Match&gt; Matches { get; set; }
      public virtual ICollection&lt;EventParticipation&gt; EventParticipation { get; set; }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>