开发者

Entity Framework 4.1 - What does RequiredAttribute really mean?

开发者 https://www.devze.com 2023-03-06 12:15 出处:网络
I\'m having a database computed field in my Code-First model. I\'ve marked that with the DatabaseGeneratedAttribute. Do I need to specify the RequiredAttribute too?

I'm having a database computed field in my Code-First model. I've marked that with the DatabaseGeneratedAttribute. Do I need to specify the RequiredAttribute too?

In other words: Does 'required' mean, that it's req开发者_如何学编程uired this value is assigned to? Or does it mean, that this value is not allowed to be null.


RequiredAttribute is used for both validation and mapping definition. If you define string property without this attribute it is defined as nullable column in the database but with this attribute it is not nullabe. In other words it says if property can contain null both during validation and in the database.

0

精彩评论

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