3
votes

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

1
Can you show us your code for the User model? - JasCav
I am having a similar issue. However .WithRequired(), .WithRequiredPrincipal(), and .WithRequiredDependent() all fail. - Anthony Gatlin
This may be a duplicate of this question/answer: stackoverflow.com/questions/10438219/… - kingdango
It may be a duplicate but it's hard to predict what questions might be asked in May when you post them in February. - Lee Smith
And still a bug in EF 5.0 RTM. - Patrick Peters

1 Answers

1
votes

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