Is it possible to set a unique constraint using Entity Framework Code First?

It appears that the unique constraint feature that was scheduled to release with Version 6 got pushed to 6.1.

With EF 6.1, you can define a constraint using the Index attribute as 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 as shown here in MSDN

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)