How can we improve Entity Framework Core?

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 →

    11 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • 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