Add-Migration Created Columns Alphabetically Asp.Net Core 2.0

asp.net-core-2.0 aspnetboilerplate c# entity-framework-core

Question

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.

1
5
9/19/2017 4:33:29 AM

Popular Answer

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

3
9/21/2017 7:11:19 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow