title: Remove duplicate entries in database using entity framework
body: <p>I am using Entity Framework 6.1 code first . I am working on a product in which the release version of the product there there are duplicate entries in a <strong>UserName</strong> column in the <strong>UserProfile</strong> table. To remove this bug I am using the Index annotation on the UserName field.</p>
  
  <pre><code>class UserProfile
  {
       [Index("IX",IsUnique=True)]
       string UserName;
       string Id;
   }
  </code></pre>
  
  <p>so that now the duplicate entry problem goes away. But I dont have backward compatibility now. As in the customers who are already using the release product and have duplicate entries in their database cannot use their existing database.</p>
  
  <p>I have created a migration using entity framework and it updates the database like this</p>
  
  <pre><code>public partial class UserConcurrencyFix : DbMigration
  {
       public override void Up()
       {
            CreateIndex("dbo.UserProfiles", "UserName", unique: true);
       }
       public override void Down()
       {
            DropIndex("dbo.UserProfiles", new[] { "UserName" });
       }
   }
  </code></pre>
  
  <p>This does not take care of existing databases that already have duplicate entries. Is there a way I can remove duplicates from databases that already being used by the users and have duplicate entries?</p>