Pergunta

How can I specify a Check Constraint in EF4 CodeFirst.

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top