Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:09:07+00:00 2026-06-03T22:09:07+00:00

Error: Unhandled Exception: System.Data.SqlClient.SqlException: The operation failed because an index or statistics with name

  • 0

Error:

Unhandled Exception: System.Data.SqlClient.SqlException: The operation failed because an index or statistics with name ‘IX_ID’ already exists on table ‘PrivateMakeUpLessons’.

Model (Simplified, building in a separate test project for debugging):

public abstract class Lesson
{
    public Guid ID { get; set; }
    public string Room { get; set; }
    public TimeSpan Time { get; set; }
    public int Duration { get; set; }
}

public abstract class RecurringLesson : Lesson
{
    public int DayOfWeek { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string Frequency { get; set; }
}

public class PrivateLesson : RecurringLesson
{
    public string Student { get; set; }
    public string Teacher { get; set; }
    public virtual ICollection<Cancellation> Cancellations { get; set; }
}

public class Cancellation
{
    public Guid ID { get; set; }
    public DateTime Date { get; set; }
    public virtual PrivateLesson Lesson { get; set; }
    public virtual MakeUpLesson MakeUpLesson { get; set; }
}

public class MakeUpLesson : Lesson
{
    public DateTime Date { get; set; }
    public string Teacher { get; set; }
    public virtual Cancellation Cancellation { get; set; }
}

Configuration:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Lesson>().ToTable("Lessons");
    modelBuilder.Entity<RecurringLesson>().ToTable("RecurringLessons");
    modelBuilder.Entity<PrivateLesson>().ToTable("PrivateLessons");
    modelBuilder.Entity<MakeUpLesson>().ToTable("PrivateMakeUpLessons");

    modelBuilder.Entity<Cancellation>()
        .HasOptional(x => x.MakeUpLesson)
        .WithRequired(x => x.Cancellation);

    base.OnModelCreating(modelBuilder);
}

Notes:

This worked fine in EF 4.2. Is there something wrong with my model? The actual model is much more complicated which is why I have all the classes abstracted out. Also, I am working against an existing database so I need to use Table-Per-Type inheritance.

If I change the relationship of Cancellation to PrivateMakeUpLesson from 1 to 0..1 to 0..1 to 0..1 it works. This is undesirable because you can’t have a PrivateMakeUpLesson without a Cancellation.

Also, if I make PrivateMakeUpLesson NOT inherit from Lesson then it also works, but it IS a lesson and needs to remain so for existing business logic.

I’d appreciate any guidance. Thank you!

Edit:

Starting a bounty. I can’t find any documentation on what changed between EF 4.2 and EF 4.3 with regard to the index generation for code first. It’s clear that EF 4.3 is creating more indexes and that the naming scheme has changed but I want to know if there’s a bug in EF or if there is something fundamentally wrong with my model or fluent API configuration.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:09:08+00:00Added an answer on June 3, 2026 at 10:09 pm

    As of EF 4.3, indexes are added for freign key columns during database creation. There is a bug that can cause an index to be created more than once. This will be fixed in a future EF release.

    Until then, you can work around the issue by creating your database using Migrations instead of database initializers (or the Database.Create() method).

    After generating the initial migration, you will need to delete the redundant call to Index().

    CreateTable(
        "dbo.PrivateMakeUpLessons",
        c => new
            {
                ID = c.Guid(nullable: false),
                ...
            })
        .PrimaryKey(t => t.ID)
        .ForeignKey("dbo.Lessons", t => t.ID)
        .ForeignKey("dbo.Cancellations", t => t.ID)
        .Index(t => t.ID)
        .Index(t => t.ID); // <-- Remove this
    

    To continue creating your database at run-time, you can use the MigrateDatabaseToLatestVersion initializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error: Unhandled Exception: System.IO.IOException: The parameter is incorrect. at System.IO.__Error.WinIOError(Int32
I am getting An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll in my
I got this error Unhandled exception at 0x0049b946 in Program.exe: 0xC0000005: Access violation reading
In my unhandled exception logging I see this error sporadically through the day on
I am getting the error Format Exception was unhandled at Do While objectReader.Peek <>
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
My problem in ie browser only... auth.js Deferred.errorHandler = function(e) { alert('Unhandled error '
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
error not firing. but its showing on firebug HTTP 500 error : jQuery15105771912402844872_1324698623378({Message:Master Order
Error : It is an error to use a section registered as allowDefinition='MachineToApplication' beyond

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.