5

I have created a model and run command Add-Migration in PMC. it created columns in alphabetically order in migration. After updating database sqlserver table are also in alphabetically order. I want the same order which i used in my original model instead of alphabetical order. I don't want to go with this.

[Key, Column(Order=0)]
public int MyFirstKeyProperty { get; set; }

[Column(Order=1)]
public int MySecondKeyProperty { get; set; }

As i have 70 properties in my table and some time it may exceed. and i am not sure it works or not. I have searched a lot and just know that it is issue with .Net Core2.0. is it ture? Any solution? Thanks.

Shahid Malik
  • 163
  • 13

2 Answers2

3

unfortunately there's no EF support for this. click here to see the open issue about this topic.

The workarounds about the issue can be;

  • You can just manually reorder the column order in the scaffolded migration.
  • There's a Github repository that programmatically solves this issue. Click here to see the EfCore.Shaman.
  • You can write your own T-SQL migration

    migrationBuilder.Sql("Create Table XYZ (FirstKeyProperty INT NOT NULL, SecondKeyProperty int NOTNULL)");

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
  • Thanks @Alper Ebicoglu, for you help. But i don't see any proper solution helpful. EfCore.Shaman. solution is little bit good approach. But i am looking help from trusted sources. There should be proper solution for this issue as it is worthy problem! – Shahid Malik Sep 18 '17 at 12:37
  • 1
    i stated all the possible solutions. and you saw the open issue about this problem on EF official repo. so no solution from trusted sources. – Alper Ebicoglu Sep 18 '17 at 12:50
  • @AlperEbicoglu Update since the issue is `closed-fixed`? – aaron Jul 01 '18 at 16:46
  • After the migration is generated, you are free re-arrange the columns in whatever order you want – Alper Ebicoglu Jul 02 '18 at 07:21
  • @AlperEbicoglu Edit your answer :) – aaron Jul 08 '18 at 13:44
0

hey guys good news they are fixing this problem

This issue has been fixed in version 2.1.0. You can try it out using the nightly builds, or wait for the 2.1.0-preview1-final release which is expected sometime this month More

bricelam commented on Feb 9

Floxy
  • 117
  • 2
  • 10