How can we improve Entity Framework or Entity Framework Core?


Create a IndexAttribute for annotating entities with index hints for the Database.
For Example

string MyProptery{Get;set;}

1,175 votes
Sign in
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Boas EnklerBoas Enkler shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


    Sign in
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      • Michael BisbjergMichael Bisbjerg commented  ·   ·  Flag as inappropriate

        [Index(Column = 0, Name = "IX_MyIndex")]
        [Index(Column = 1, Name = "IX_MyIndex")]
        [Index(Column = 2, Name = "IX_MyIndex")]

        Remember column ordering, people :)

      • Jim WolffJim Wolff commented  ·   ·  Flag as inappropriate

        I forgot to add, it is easily possible via code first migrations, but having the attribute or the fluent api would make auto generation of the index possible when making the migration.

      • MarcMarc commented  ·   ·  Flag as inappropriate

        Agreed, but can we not forget about the designer please? Some of us actually prefer model first!

        The ability to generate indexes on a column is needed, but also a way of setting it from the designer.

      • Kevin PietteKevin Piette commented  ·   ·  Flag as inappropriate

        As a workaround we've been adding unique and non-unique indexes to the migrations (using the fluent Index() methods supported for migrations). Sort-order support requires other ModelBuilder specializations described elsewhere.

        This isn't ideal since the manual mods are lost during development if the migration is regenerated but at least allows the indexes to be reflected in code.

      • Ken DemarestKen Demarest commented  ·   ·  Flag as inappropriate

        Lack of ability to use Annotations or Fluent to create indexes is a black mark on the entire Entity Framework team. Do you think ANYONE writing code doesn't need to add indexes? Really?

      • ЭлькеносЭлькенос commented  ·   ·  Flag as inappropriate

        More once: included columns if it possible.


        public long Id { get; set; }
        public string Name { get; set; }

      • AnonymousAnonymous commented  ·   ·  Flag as inappropriate

        Only one thing - this SHOULD be in the FluentAPI only, not in Attribues. Because it's SQL-dependend and you should not mix it with model.

      • HOONSHOONS commented  ·   ·  Flag as inappropriate

        It would be helpful, if EF could attach Unique and Clustered options.
        like bellow:

        int A { get; set; }

      • Ricardo PeresRicardo Peres commented  ·   ·  Flag as inappropriate

        I agree this is a must have!
        Other required properties:

        - Clustered/unclustered;
        - Unique;
        - Group name (to allow indexes over many properties; if it is empty, it applies to just the property where it is declared; if it is not empty, all properties with the same group name are added to the index definition.

        This has some problems, however:

        - The actual column name may be explicitly defined in configuration by code;
        - The actual SQL to use for index creation depends on the current DB engine.

        Hope the Entity Framework team can do something about these problems, this is quite necessary!

      • John GaltJohn Galt commented  ·   ·  Flag as inappropriate

        This should also be added to Fluent API so that we can create composite indexes as needed as well.

        The only other thing that needs to be added is an SQL Specific annotation for FileTables and Filestreams!

      • mousedocmousedoc commented  ·   ·  Flag as inappropriate

        This is drastically needed to prevent having to manually modify auto-generated migration code that can be wiped out when starting over on a new database.

      Feedback and Knowledge Base