Efcore: Support an [Index] attribute

Created on 11 Dec 2015  路  11Comments  路  Source: dotnet/efcore

We didn't bring this over from EF6.x because it had a lot of issues... but opening this issue to track the possibility of adding it in the future since a number of folks have asked for it (see discussion on #1698).

closed-fixed punted-for-3.0 type-enhancement

Most helpful comment

We didn't bring this over from EF6.x because it had a lot of issues...

I'm not sure about what problems are there due to I had not learned more about it. Anyway, I could not forget Index attribute...

So that, I create my own Index attribute library, and published it.

https://www.nuget.org/packages/Toolbelt.EntityFrameworkCore.IndexAttribute

This library allows us to easy way to recognize models without round trip between DbContext class and Entity classes.

I hope, this library to be useful for some people who could not forget Index attribute, and I hope it does not bother the developer community.

All 11 comments

We didn't bring this over from EF6.x because it had a lot of issues...

I'm not sure about what problems are there due to I had not learned more about it. Anyway, I could not forget Index attribute...

So that, I create my own Index attribute library, and published it.

https://www.nuget.org/packages/Toolbelt.EntityFrameworkCore.IndexAttribute

This library allows us to easy way to recognize models without round trip between DbContext class and Entity classes.

I hope, this library to be useful for some people who could not forget Index attribute, and I hope it does not bother the developer community.

LOL @ "because it had lot of issues". Thanks for providing solution @jsakamoto

Inception when I see #1698

@jsakamoto awesome !

It would be really nice to move/add IndexAttribute to the System.ComponentModel.Annotations or Microsoft.EntityFrameworkCore.Abstractions package, and align the attribute for EFCore vNext and EF6.3 to allow the use of annotations on the model, without forcing an ORM provider.

This would allow for migrating our existing app piecemeal, and re-using the model both server side (ASP.NET MVC5/WebAPI2/EF6) and in our offline client side apps (Xamarin.Forms)

Right now we are using a home grown solution similar to @jsakamoto's Toolbelt.EntityFrameworkCore.IndexAttribute but with our own abstractions package, an EF6 Convention in another package, and an EFCore ModelBuilder 'convention' in a third.

@CZEMacLeod we definitely intend to have an attribute-based method to define indices in EF Core, but it's unlikely this would reuse the IndexAttribute found in System.ComponentModel.Annotations or be the same across EF6 and EF Core. Among other things, that attribute has the SQL Server-specific property IsClustered(), and we're looking at more usable ways to define composite indices. But no decisions have been made yet.

@CZEMacLeod Also, the design of the Index attribute in EF6 is not very good, but we're not going to change it for EF6, so Core will definitely have a new attribute.

Would be nice to have an IsUnique modifier too.

I know you guys are super busy and have a lot of work to do at the moment but can someone please expand why this was taken out of the 3.0 release? Any idea when it might be placed in a different release?

@tidusjar It was taken out because we don't have enough resources to complete it in time for 3.0. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@lajones - Can you put a small design of IndexAttribute which is implemented, how to use it and limitations on it here (and also edit the first post to add it at the top). If you are planning to add it to docs next, then the link to docs site page would also be fine. It would make it easier for people who ends up here searching for this issue to know what we implemented.

@lajones - Can you put a small design of IndexAttribute which is implemented, how to use it and limitations on it here (and also edit the first post to add it at the top). If you are planning to add it to docs next, then the link to docs site page would also be fine. It would make it easier for people who ends up here searching for this issue to know what we implemented.

See the docs issue I just added.

Was this page helpful?
0 / 5 - 0 ratings