Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique constraint in Entity Framework [duplicate]

Tags:

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.

like image 700
Cartesius00 Avatar asked May 18 '11 21:05

Cartesius00


People also ask

How do you avoid duplicates in Entity Framework?

You can avoid duplicate values by setting an index property to yes and u can do this by right clicking a particular entity and click edit entity and set the index property to yes.


1 Answers

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.

like image 81
Ladislav Mrnka Avatar answered Oct 26 '22 02:10

Ladislav Mrnka