Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add-Migration Created Columns Alphabetically Asp.Net Core 2.0

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.

like image 312
Shahid Malik Avatar asked Oct 17 '22 05:10

Shahid Malik


1 Answers

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)");

like image 59
Alper Ebicoglu Avatar answered Oct 29 '22 17:10

Alper Ebicoglu