سؤال

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