IndexAttribute
Create a IndexAttribute for annotating entities with index hints for the Database.
For Example
[Index(Direction.Ascending)]
string MyProptery{Get;set;}
11 comments
-
Jim Wolff
commented
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.
-
Jim Wolff
commented
There are several suggestions on this in a question i posted on stackoverflow on the subject:
I think EF needs to have both an index attribute and a way to configure it via EntityTypeConfigurations and the fluent api.
-
Marc
commented
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
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
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
More once: included columns if it possible.
e.g.:
[Indexed]
[IncludedColumn("Name")]
public long Id { get; set; }
public string Name { get; set; } -
Anonymous
commented
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
It would be helpful, if EF could attach Unique and Clustered options.
like bellow:[Indexed(Unique=false,Clustered=false)]
int A { get; set; } -
Ricardo Peres
commented
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
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
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.