c# - Entity Framework 4.1 - RequiredAttribute 的真正含义是什么?

标签 c# data-annotations ef-code-first entity-framework-4.1

我的 Code-First 模型中有一个数据库计算字段。我已经用 DatabaseGeneratedAttribute 标记了它。我还需要指定 RequiredAttribute 吗?

换句话说:'required' 是否意味着必须将此值分配给?还是表示此值不允许为空。

最佳答案

RequiredAttribute 用于验证和映射定义。如果您在没有此属性的情况下定义 string 属性,则它在数据库中被定义为可为空的列,但如果有此属性,则它不是 nullabe。换句话说,它表示属性是否可以在验证期间和数据库中包含 null

关于c# - Entity Framework 4.1 - RequiredAttribute 的真正含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6020056/

相关文章:

c# - Entity Framework 控制台应用程序连接到错误的数据库

c# - 使用 SignalR Core 将消息从 Controller 方法发送到 Angular

c# - "=="运算符的行为不像编译器生成的匿名类型的 Equals() 覆盖

c# - 用dapper查询oracle的集合参数

c# - 自定义 404 错误消息 ASP.NET Visual Studio

c# - 属性为 [Required] 且可为 null 是什么意思?

asp.net-mvc - Asp.Net MVC : Some un-localized default error message?

asp.net-mvc - ASP.Net Mvc 定长字符串数据注解

entity-framework - 如何预编译 Entity Framework 代码优先查询?

c# - 升级到 Entity Framework 4.3.1 后未处理的异常