title: Can I get a primary key to auto-increment in Entity Framework, while having other key
body: <p>I'm working on a MVC project with Entity Framework and VS 2015.</p>
  
  <p>It has worked so far. Now I've made a relation table-entity to link between two tables, and I can't get the Key-column to auto-increment. It was because I didn't want to remove some constraints in the existing tables that I chose to make a separate entity.</p>
  
  <p>It looks like this:</p>
  
  <pre><code>public class UserCustomer
  {
  
      [Key]
      public int UserCustomerID { get; set; }
      [Index("IX_UserAndCustomer", 1, IsUnique = true)]
      public int UserID { get; set; }
      [Index("IX_UserAndCustomer", 2, IsUnique = true)]
      public int CustomerID { get; set; }
  
      public DateTime CreatedDate { get; set; }
  
      public UserCustomer()
      {
          CreatedDate = DateTime.Now;
      }
  
  }
  </code></pre>
  
  <p>The key column doesn't become auto-incremented.</p>
  
  <p>I've tried Fluent API with, for example:</p>
  
  <pre><code>        //modelBuilder.Entity&lt;UserCustomer&gt;()
          //    .HasKey(u =&gt; new { u.CustomerID, u.UserID }); //26 maj -17
  
          //modelBuilder.Entity&lt;UserCustomer&gt;()
          //.Property(f =&gt; f.UserCustomerID)
          //.ValueGeneratedOnAdd();
  
          //modelBuilder.Entity&lt;UserCustomer&gt;()
          //    .Property(c =&gt; c.UserCustomerID)
          //    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);//TYY Stack Overflow
  </code></pre>
  
  <p>But this hasn't worked.</p>
  
  <p>How do I make the UserCustomerID column auto-increment, as a key-column?</p>