IndexAttribute
Create a IndexAttribute for annotating entities with index hints for the Database.
For Example
[Index(Direction.Ascending)]
string MyProptery{Get;set;}
Reopening since this was originally completed for EF6 but the feature is not available to Entity Framework Core.
15 comments
-
Matthew Verstraete commented
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
-
Anonymous commented
This has been added now to EF 6.1 beta: http://blogs.msdn.com/b/adonet/archive/2014/02/11/ef-6-1-0-beta-1-available.aspx
-
Michael Bisbjerg commented
[Index(Column = 0, Name = "IX_MyIndex")]
[Index(Column = 1, Name = "IX_MyIndex")]
[Index(Column = 2, Name = "IX_MyIndex")]Remember column ordering, people :)
-
Karl Dodd commented
Learn from the XBOX team and listen to the users. plz.
-
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.