efcore: Migrations: Column order incorrect in CreateTable when using interfaces

With respect to pull request that is dealing with issue and my duplicate, I can report that it indeed creates proper “CreateTable” code for InitialCreate.cs, but at the same time the code for InitialCreate.Designer.cs is not properly created. This causes table not to be created with proper column order.

This is InitialCreate.cs output (and order of columns is correct):

migrationBuilder.CreateTable(
                name: "UserTask",
                schema: "Configurations",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ClientId = table.Column<byte>(nullable: false),
                    ModuleId = table.Column<int>(nullable: false),
                    TaskId = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: false),
                    ModifiedBy = table.Column<string>(maxLength: 100, nullable: false),
                    LastModification = table.Column<DateTime>(type: "datetime", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserTask", x => x.Id);
                });

This is “InitialCreate.Designer.cs” output (and order of columns is NOT correct):

modelBuilder.Entity("MongoPlus.Domain.Models.Subscription.Configurations.UserTask", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<byte>("ClientId");

                    b.Property<DateTime>("LastModification")
                        .HasColumnType("datetime");

                    b.Property<string>("ModifiedBy")
                        .IsRequired()
                        .HasMaxLength(100);

                    b.Property<int>("ModuleId");

                    b.Property<int>("TaskId");

                    b.Property<int>("UserId");

                    b.HasKey("Id");

                    b.ToTable("UserTask","Configurations");
                });

When I run “Update-Database -Context SubscriptionDbContext”, I get table created with column order as coded in “InitialCreate.Designer.cs”, and that means that that issue should be reopened.

Further technical details

EF Core version: 2.1.0 Preview 2 Database Provider: Microsoft SQL Operating system: Windows 10 IDE :Visual Studio 2017 15.7 Preview

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 17 (13 by maintainers)

Most upvoted comments

@ajcvickers I understand your point. Even though, imagine someone with 100 tables (like me) to do that manual sorting. I hope it will be in the next release though. Thanks for the update.