0

I want the following database table:

[Id] [BookType] [Hardcover]

But only when booktype is 1, hardcover may not be null. So whenever booktype is 2 or 3 I should be able to give a null value to hardcover.

Is there anything in my database where I can set this kind of rule?

1 Answer 1

1

Your hardcover column must accept null to support type 2 and 3. It is application rule not database rule. You must validate in the application that entity with book type = 1 always has a value set to hardcover.

If you defined inheritance and you have separate type for book of type 1 you can try to make Hardcover property non nullable in the model (but it will most probably don't work with the code first approach).

Sign up to request clarification or add additional context in comments.

1 Comment

I'm using model first at the moment. I already got inheritance so I'll try to make it not nullable for the subtype. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.