asp.net mvc - Is it possible to set a unique constraint using Entity Framework Code First? -
i want enforce unique constraint in table & using entity framework code-first.
is possible add unique constraint using ef 6 believe in earlier versions not possible.
it appears unique constraint feature scheduled release version 6 got pushed 6.1.
with ef 6.1, can define constraint using index attribute shown below:
[index("ix_firstandsecond", 1, isunique = true)] public int firstcolumn { get; set; } [index("ix_firstandsecond", 2, isunique = true)] public int secondcolumn { get; set; }
or
you can use fluent api shown here in msdn