対象のカラムにIndexアノテーションをつけて終了。
/*
using System.ComponentModel.DataAnnotations.Schema;
*/
[Index(IsUnique = true)]
public string Email { get; set }
と思ったら、上記のようにstring型に対してUniqueを設定すると、Databaseマイグレーション時に以下のようなエラーが出る。
Column 'Email' in table 'dbo.Users' is of a type that is invalid for use as a key column in an index.
原因は、SQLServerの index key の最大長が900Byteだからとのこと。
ということで、カラムに最大長を設定してあげることで解決する。
最終的にはこちら。
/*
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
*/
[Index(IsUnique = true)]
[StringLength(256)]
public string Email { get; set }
参考(というかそのまま)
http://stackoverflow.com/questions/10614575/entity-framework-code-first-unique-column