开发者

Entity data model, unique index

开发者 https://www.devze.com 2023-01-21 17:54 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消