Search for existing suggestions

EF Core Migrations Column ordering

Migrations on EF Core should do Scaffolding of the fields of entity like the order of the entity (and NOT alphabetical)

As this req:
https://github.com/aspnet/EntityFramework/issues/2272
and
https://github.com/aspnet/Scaffolding/issues/398

141 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    19 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Anonymous commented  ·   ·  Flag as inappropriate

        Has this been rectified, I just tried the latest 2.1 preview, no luck, this functionality is not working correctly, and I cannot report ERDs that look disorganized to my superiors. I have had to remove my based columns on all 23 entities I have and re-add them on entity at the end, multiple migrations just to get order working on the columns. Im so close to revert to EF 6.2, it was more stable

      • 3W3450N commented  ·   ·  Flag as inappropriate

        Preciso que a ordem da criação do banco de dados ocorra de acordo com a ordem do modelo isso deveria ser uma opção e não obrigação, caso contrário as o campos das tabelas do banco de dados ficarão uma zona. Olhem para isso urgente.

      • AdminDiego Vega (Program Manager, Microsoft Entity Framework) commented  ·   ·  Flag as inappropriate

        @Ivan, I see an interesting point implied in your last comment: The new feature in EF Core 2.1 is only about ordering of columns for the CREATE TABLE statements generated by migrations. It does not affect column ordering for any other generated SQL.

        Assuming that you (or anyone else in this thread) care about order of columns in let's say the SQL generated from LINQ queries that project whole entities, please create an issue on https://github.com/aspnet/entityframeworkcore/issues/new. Please provide details about why this is important to you.

        On your original intent, yes I think I understood what you wanted right after reading your first comment. My point is that this cannot be implemented in the way you described because there is no such thing as TotalColumns.

      • Ivan commented  ·   ·  Flag as inappropriate

        @DiegoVega, I was referring to the TotalColumns as an option to have the columns order as the last columns of any table, my idea is to preserve that order for all entites at the end of a select, so every time you make a select you will see for example IsDeleted as the last column of your data. It is something that I can achieve in other way?

      • AdminDiego Vega (Program Manager, Microsoft Entity Framework) commented  ·   ·  Flag as inappropriate

        @Ivan, What you propose doesn't seem viable: Attributes declarations can only reference very simple expressions. Any identifiers need to exist and be of the right type. What is TotalColumns? If we ever implement this kind of fine control for columns ordering (which doesn't seem a high priority given that we cannot guarantee the order will be preserved after the first table creation), we would probably use a different approach.

      • Ivan commented  ·   ·  Flag as inappropriate

        I would like to have instead of the bellow class

        public class MyClass
        {
        [Column(Order = 1)]
        public string Colunm1{get;set;}
        [Column(Order = 2)]
        public string Colunm2{get;set;}
        [Column(Order = 3)]
        public string Colunm3{get;set;}
        [Column(Order = 4)]
        public bool IsDeleted{get;set;}
        }

        an option with the total number of columns, something like this

        public class MyClass
        {
        public string Colunm1{get;set;}
        public string Colunm2{get;set;}
        public string Colunm3{get;set;}
        [Column(Order = TotalColumns)]
        public bool IsDeleted{get;set;}
        }

        where column1 and 2, 3 should be listed in the order they appear but before IsDeleted. Even if you have more columns you can specify at least the latest columns in the table

        [Column(Order = TotalColumns - 1)]

      • Mike V commented  ·   ·  Flag as inappropriate

        This really needs to be an option. Also a way to designate where base entity fields appear in the table.

      • Ivan Farkas commented  ·   ·  Flag as inappropriate

        The "dnx . ef migration add initial" command of ASP.NET 5/EF 7 should generate columns in same order as the properties appear in the entities.
        Currently they are in alphabetical order.

      Feedback and Knowledge Base