title: Entity Framework Code first : Set unique key constraint is not working
body: <p>In my application I am using EntityFramework with code first approach. I am using EF7 with ASP.NET 4.6 MVC and VS2015. My model class is like below :</p>
  
  <pre><code>public class Customer
  {
      public int CustomerID { get; set; }
  
      [StringLength(100)]
      [Required]
      public string FirstName { get; set; }
  
      [StringLength(100)]
      [Required]
      public string LastName { get; set; }
  
      [Required]
      [EmailAddress(ErrorMessage = "Please enter valid Email Address.")]
      [StringLength(100)]
      [Index("IX_EA", IsUnique = true)]
      public string EmailAddress { get; set; }
  
  }
  </code></pre>
  
  <p>My context file is like below : </p>
  
  <pre><code>public class CustomerContext : DbContext
  {
      public CustomerContext()
      {
          Database.EnsureCreated();
      }
      public DbSet&lt;Customer&gt; Customers { get; set; }
      protected override void OnConfiguring(DbContextOptionsBuilder options)
      {    
          var connection = System.Configuration.ConfigurationManager.ConnectionStrings["DbConnectionString"].ConnectionString;
          options.UseSqlServer(connection).UseRowNumberForPaging();
      }
  }
  </code></pre>
  
  <p>So, from model class you can see that I want set unique constraint to EmailAddress column in database table means EmailAddress field should contain duplicate value(an email address should not be repeat in table). But when I run the project database successfully get created. but that Unique constraint in not there. I am not getting why it is not setting that constraint on EmailAddress field.</p>
  
  <p>Please help me to set unique constraint to the field using code first approach of EntityFramework.</p>