Everything worked fine in previous versions but now in 4.3 I get this error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.DLL but was not handled in user code
Additional information: The operation failed because an index or statistics with name 'IX_Id' already exists on table 'Users'.
The User table has an Id property and is the primary key but I'm not using code or attributes anywhere else to create an additional index??
User Model:
public class User
{
public int Id { get; set; }
public virtual Settings Settings { get; set; } /* 1-1 */
public virtual Profile Profile { get; set; } /* 1-1 */
public virtual Account Account { get; set; } /* 1-1 */
}
It's failing here in my OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<User>().HasRequired(u => u.Settings).WithRequiredDependent();
modelBuilder.Entity<User>().HasRequired(u => u.Profile).WithRequiredDependent();
modelBuilder.Entity<User>().HasRequired(u => u.Account).WithRequiredDependent();
Update: just fixed it by using WithRequiredPrincipal instead of WithRequiredDependent. Not sure why this is different in 4.3
This is a bug in EF 4.3. It will be fixed in EF5 RTM. For more information including a workaround see this question: Unhandled Exception after Upgrading to Entity Framework 4.3.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With