I'm using Entity Framework 6.1.1 and Code first. EF 6.1 should have added support for the Index attribute, but neither the editor auto-completion or compiler accept the [Index] attribute such as:
[Index]
public DateTime TimeOfSale { get; set; }
All project references point to the DLLs for EF 6.1.1.
I'm also running SQL Server Compact Edition 4.0.
How to enable the use of the new [Index] attribute?
While the KeyAttribute
is in the System.ComponentModel.DataAnnotations
namespace, the IndexAttribute
class is in the System.ComponentModel.DataAnnotations.Schema
namespace. You are likely missing the following using
statement:
using System.ComponentModel.DataAnnotations.Schema;
Note if you are working in ASP.NET Core as of this writing the Index attribute is not supported. An alternative is nicely outlined in this SO post though: Asp.net Core Entity Framework cannot find IndexAttribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With