This is my first time exploring DataAnnotations (I was hoping to use this over fluent)...and I don't understand why the following code throws a compile time error:
CS0592 - Attribute 'Index' is not valid on this declaration type. It is only valid on 'class' declaration
public class Holiday
{
[Key]
public int Id { get; set; }
[Required]
[Index(IsUnique = true)]
public DateTime? Date { get; set; }
public string Name { get; set; }
}
My goal is to make the Date column UNIQUE...and I thought using [Index(IsUnique = true)] on a column is the correct way to make it unique...but it is not allowing me to use the Index attribute on columns, only on classes...
Please teach me how to achieve this?