title: How to use Auto Increment in Entity Framework 5, when seeding data?
body: <p>I would like to seed data to my database after each database schema update , but  I have trouble solving an issue with my seeding functionality. My (value) class looks like this</p>
  <pre><code>public class ObjectInstance
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ObjectInstanceId { get; set; }
     
      [Column(TypeName = &quot;NVARCHAR&quot;)]
      [StringLength(255)]
      public string ObjectInstanceTitle { get; set; }
  }
  </code></pre>
  <p>I have set the necessary attributes on my key column - I think.</p>
  <p>In my <code>DbContext</code> I have the following function:</p>
  <pre><code>protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;ObjectClass&gt;(b =&gt;
          {
              b.HasKey(e =&gt; e.ObjectClassId);
              b.Property(e =&gt; e.ObjectClassId).ValueGeneratedOnAdd().UseIdentityColumn(0, 1);
  
              b.HasData(
                  new ObjectClass
                  {
                      ObjectClassTitle = &quot;Object&quot;,
                      ObjectClassDescription = &quot;Root object&quot;,
                      OfType = 1
                  },
                  new ObjectClass
                  {
                      ObjectClassTitle = &quot;Object&quot;,
                      ObjectClassDescription = &quot;Root object&quot;,
                      OfType = 1
                  }
              );
          });
      }
  </code></pre>
  <p>No matter what I try to do, I get the following error:</p>
  <blockquote>
  <p>The seed entity for entity type 'ObjectClass' cannot be added because a non-zero value is required for property 'ObjectClassId'. Consider providing a negative value to avoid collisions with non-seed data.</p>
  </blockquote>
  <p>Thanks in advance.</p>