开发者

Entity Framework - Inheritance Null Value

I want the f开发者_开发问答ollowing 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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜