You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@euyuil I am not familiar enough with the MySQL provider to know for sure, but this might be an expected limitation if support for index migrations operations was not implemented. If you can prove that this works with SQL Server but not with MySQL, I would encourage you to file a bug. I believe https://bugs.mysql.com/ is the right place to do so.
EF Team Triage: Closing as with the current information we believe this issue is external to EF and not actionable for the EF team. Hopefully the information provided can help redirect the issue to the owners of the MySQL provider where it can be addressed.
I haven't tested with SQL Server yet and am not sure if the issue is only for MySQL.
Package versions:
Simplified code:
I expect the table to be created with a primary key
Id
and a unique index for columnMobile
. But the result was that a primary key index forId
was created, and a redundant unique index forId
was also created, but the expected unique index forMobile
was not.Screenshots from MySQL Workbench:
Full code and project files:
eftest.zip
The text was updated successfully, but these errors were encountered: