Bug #82828 IndexAttribute or IndexAnnotation not working while initializing MySQL
Submitted: 31 Aug 2016 20:09 Modified: 4 Apr 2017 10:05
Reporter: Gabriela Martinez Sanchez Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.9.9 OS:Any
Assigned to: CPU Architecture:Any

[31 Aug 2016 20:09] Gabriela Martinez Sanchez
Description:
From the issue reported in github (https://github.com/aspnet/EntityFramework6/issues/51#event-774133112)

I haven't tested with SQL Server yet and am not sure if the issue is only for MySQL.

Package versions:

EntityFramework 6.1.3
MySql.Data 6.9.9
MySql.Data.Entity 6.9.9
Simplified code:

public class MyDbContext : DbContext
{
    public MyDbContext() : base("MyDbContextConnectionString")
    {
        Database.SetInitializer(new MyDbInitializer());
    }

    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        // The following code doesn't work either.
        // modelBuilder.Entity<User>()
        //     .Property(e => e.Mobile)
        //     .HasColumnAnnotation(
        //         IndexAnnotation.AnnotationName,
        //         new IndexAnnotation(new IndexAttribute("IX_Mob") { IsUnique = true }));
    }
}

public class MyDbInitializer : DropCreateDatabaseAlways<MyDbContext>
{
}

public class User
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Id { get; set; }

    [Required]
    public string Name { get; set; }

    [Required]
    [Index(IsUnique = true)]
    public string Mobile { get; set; }
}

internal static void Main(string[] args)
{
    using (var context = new MyDbContext())
    {
        // ...
    }
}
I expect the table to be created with a primary key Id and a unique index for column Mobile. But the result was that a primary key index for Id was created, and a redundant unique index for Id was also created, but the expected unique index for Mobile was not.

How to repeat:
Please see description.

Suggested fix:
NA
[4 Apr 2017 10:05] Chiranjeevi Battula
Hello  Gabriela,

Thank you for the bug report.

Thanks,
Chiranjeevi.