質問

How can I specify a Check Constraint in EF4 CodeFirst.

Example: I have a string property for which I can have only specific values.

役に立ちましたか?

解決

EF code first doesn't have any equivalent for check constraints. If you want to have check constraint in the database you can either use custom database initializer and execute custom SQL to alter table and add check constraint (I described similar approach for unique index here) or if you are already using EF code first migrations you can add constraint creation to your Up method in code based migration.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top