Search for existing suggestions


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

string MyProptery{Get;set;}

486 votes
Sign in
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

Boas Enkler shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: Facebook Google
Signed in as (Sign out)
  • Matthew Verstraete commented  ·   ·  Flag as inappropriate

    I am currently migrating a project over to Core and because EF Core does not support these I now have to go though hundreds of classes to find all my unique indexes and write out API calls. This is extremely annoying. Please add this back ASAP. Core is missing so many features that that 6 has that I don't even recommend core at my company as it is so lacking in ability

  • Michael 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 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.

  • Marc 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 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 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; }

  • Anonymous 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.

  • HOONS commented  ·   ·  Flag as inappropriate

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

    int A { get; set; }

  • Ricardo 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 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!

  • mousedoc 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