EF code first error "The specified index already exists. [ IX_Id ]" for object tree
- by PascalN
Using EF code first 4.3 I'm trying to model an object tree with a required-required relationships and a required-optional relationships.
Here is a simple representation of those classes
public class Top
{
public int Id { get; set; }
public virtual Middle Middle { get; set; }
}
public class Middle
{
public int Id { get; set; }
public virtual Child Child { get; set; }
}
public class Child
{
public int Id { get; set; }
}
Here is the OnModelCreating code
modelBuilder.Entity<Top>().HasRequired(t => t.Middle).WithRequiredPrincipal().WillCascadeOnDelete();
modelBuilder.Entity<Middle>().HasRequired(t => t.Child).WithOptional().WillCascadeOnDelete();
This produces the error "The specified index already exists. [ IX_Id ]" on SQLCE
After checking the db schema, both model binder fluent API configuration lines create an index IX_Id on the table Middles.
Does anyone know how to work around that problem?
Is there a way to set the index name?
Thank you!
Pascal