title: How do I temporarily turn off an IDENTITY column in EF Code First?
body: <p>I'm creating a rewrite of an existing application in EF Code First, but I need to import some of the data from the existing application's database.  Here's the definition of my entity class:</p>
  
  <pre><code>public class Business : EntityBase
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int AccountNumber { get; set; }
  </code></pre>
  
  <p>Now, the imported records need to retain their <code>AccountNumber</code> value from the old system.  However, new values should use the <code>IDENTITY</code> value generated by the DB.</p>
  
  <p>How do I turn off the <code>IDENTITY</code> while I'm importing old records, then turn it back on for the remainder of the lifetime of the application?  Executing this before importing the records has no effect:</p>
  
  <pre><code>context.Database.ExecuteSqlCommand("set identity_insert Businesses on");
  </code></pre>