Unique constraint in Entity Framework [duplicate]
How can one set some attribute in Entity (Entity Framework) to be unique? One possibility would be to make it primary key but that's not what I want.
Entity framework doesn't support unique keys so the only way is to set the unique constraint / index in the database. It will not ensure uniqueness in the application when you try to insert / update records but the exception will be fired if you try to save non unique value to the database.
http://blogs.msdn.com/b/efdesign/archive/2011/03/09/unique-constraints-in-the-entity-framework.aspx
also see Unique keys in Entity Framework 4
精彩评论