Entity Framework 7: An anonymous type can not have multiple properties with the same name


In the past I've had problems (1, 2, 3) with Entity Framework when swapping between development machines, so I wanted to get something simple up-and-running with Entity Framework 7 RC1 Update 1 to see if things were easier.

I copied an Azure database locally and then used the DNX command

dnx ef dbcontext scaffold "Server=MYDESK;Database=mydatabase;Trusted_Connection=True;" EntityFramework.MicrosoftSqlServer --outputDir Models

This created the data model classes and the context class. I checked that in and have now swapped to another machine and checked out the code. On the new machine it fails to build throwing an error in the code generated by Entity Framework 7:

protected override void OnModelCreating(ModelBuilder modelBuilder)
    modelBuilder.Entity<Items>(entity =>
        entity.ToTable("Items", "myapi");

        entity.HasIndex(e => new { e.CreatedAt, e.CreatedAt, e.CreatedAt, e.CreatedAt }).HasName("IX_CreatedAt");

The build error, on that last line, is "An anonymous type cannot have multiple properties with the same name". Why is Entity Framework 7 generating code that will not build and how do I fix it?

It looks like this is a known bug: SQL Server scaffolding generates invalid anonymous types for indexes (rc1-final) #3847, caused by "conflating indexes which had the same name but were on different tables". It is fixed in more recent commits to the milestone Entity Framework 7 RC2 (roadmap).