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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With