IN EF can I add a check constraint so if my CustomerNotes entity has a boolean “FollowUpRequired” property I force user to enter a valid future date in the “FollowUpDate” property?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EF does not support Check Constraints prior to EF Core 3.
That is, you cannot apply an attribute to an entity, and expect it to generate the appropriate SQL to create the Check constrint in the underlying database.
One way around this when using Code First Data Migrations is to generate a migration and add an
Sql()line in theUp()function override that is generated.e.g.
Also see this question and answer for some further information:
Is it possible to express a check constraint?