I am trying to make a column as Unique key in my model.
my code is :
public class Customer
{
[Index("abcd",IsUnique = true)]
public int CustomerID { get; set; }
}
and I am using following references:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
Still i am getting
Error 103 The type or namespace name 'IndexAttribute' could not be found (are you missing a using directive or an assembly reference?)
Am i missing anything? Iam using EF 6.1 version
Thanks in advance
Rephrase my answer. (apologies if shortened URL's are now allowed)
In .net 4.5 the Index attribute only exists in the file (EntityFramework.dll)
The Dll System.ComponentModel.DataAnnotations.Schema does not contain the Index attribute
The EntityFramework.dll version 6 or later contains this attribute
Browse to the file EntityFramework.dll and add a reference the error will vanish and the code will compile.
The namespace System.ComponentModel.DataAnnotations.Schema is also part of this EntityFramework.dll
I assume its a blunder by Microsoft and may be corrected in .net 5