Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity data model, unique index

In my entity data model I have an entity with one property as the primary key and another property that will have unique values too, so I’d like to create a unique index on that other property. The situation is very similar to the Person entity with the PersonID and PersonSSN fields.

Is there any way to specify in the designer or in the edmx file that such index should be created on a property when generating database from the model?

like image 884
Ivan Gerken Avatar asked Oct 22 '10 13:10

Ivan Gerken


1 Answers

Unfortunately EF4 does not support the UNIQUE constraints. The certain property can be marked as EntityKey, however, EF does not have any attribute to mark a column as unique in the .edmx file.
By the same token, when you create a unique constraint in you data store and update your model from database (in a typical database-first approach), that Unique constraint is not get picked up by the EDM.
If you want to use Model First feature of EF4 to generate the DDL, then you need to add the UNIQUE constraints to certain columns manually in the generated DDL.

like image 191
Morteza Manavi Avatar answered Sep 22 '22 20:09

Morteza Manavi