原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-first.aspx

Required 属性可以应用于域类的属性。 EF Code First将在数据库表中为我们应用Required属性的属性创建一个NOT NULL列。 请注意,它也可以与ASP.Net MVC一起用作验证属性。

请看以下示例:

using System.ComponentModel.DataAnnotations;

public class Student
{
public Student()
{ }
public int StudentID { get; set; } [Required]
public string StudentName { get; set; } }

如上面的代码所示,我们将Required属性应用于Student Name。 所以,Code First将在Student表中创建一个NOT NULL Student Name列,如下所示:

【译】第13节---数据注解-Required的更多相关文章

  1. 【译】第20节---数据注解-InverseProperty

    原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...

  2. 【译】第19节---数据注解-NotMapped

    原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...

  3. 【译】第18节---数据注解-ForeignKey

    原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...

  4. 【译】第17节---数据注解-Column

    原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...

  5. 【译】第16节---数据注解-Table

    原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...

  6. 【译】第15节---数据注解-StringLength

    原文:http://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code- ...

  7. 【译】第14节---数据注解-MaxLength/MinLength

    原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...

  8. 【译】第12节---数据注解-ConcurrencyCheck

    原文:http://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-in-c ...

  9. 【译】第11节---数据注解-TimeStamp

    原文:http://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code-fir ...

随机推荐

  1. RNN实例

    https://blog.csdn.net/jmh1996/article/details/78821216

  2. grouping sets 的使用

    grouping sets 可以用于在计算分组聚合函数值的同时计算合计值 -- 查询结果group_id为NULL的那一行即为合计值 select group_id , count(distinct ...

  3. bind的封装

    1.bind.call.apply三者的区别: 1)bind的返回值是一个函数体,不会被立即调用 2)call.apply会立即调用,第一个参数都是用来改变this的指向,两者的区别是前者传递参数的时 ...

  4. jsky使用小记

    jsky是一款深度WEB应用安全评估工具,能轻松应对各种复杂的WEB应用,全面深入发现里面存在的安全弱点. jsky可以检测出包括SQL注入.跨站脚本.目录泄露.网页木马等在内的所有的WEB应用层漏洞 ...

  5. 第一节 JavaScript概述

    第一节 JavaScript概述 JavaScript:其实就是对HTML+CSS静态页面进行样式修改,使其实现各种动态效果. 编写JS脚本基本步骤: 1. HTML+CSS静态布局: 2. 确定要修 ...

  6. [Android相机]通过手机摄像头识别环境亮度(转)

    源: [Android相机]通过手机摄像头识别环境亮度 iOS利用摄像头获取环境光感参数

  7. Vim常用命令:移动 跳转 到 文档开头或末尾

    gg:命令将光标移动到文档开头 G:命令将光标移动到文档末尾 vi编辑器中在命令行模式下输入G可以直接跳转到页面的底部 在命令行模式下输入1G可以跳转到页面的头部位置 更多在vi中移动编辑位置的命令说 ...

  8. Python3.6.2在线安装pymysql模块

    我是一个python新手刚才使用python写邮件发送代码的时候想着需要连接数据库, 下面的安装步骤 python -m pip install pymysql PS C:\Users\hp> ...

  9. kali linux 2.0配置更新源后apt-get update 报错

    这个是我/etc/apt/sources.list的更新源: deb http://http.kali.org/kali kali-rolling main contrib non-free deb ...

  10. kali linux web程序集简述

    Burp Suite Burp Suite是一个用于执行Web应用程序安全性测试的集成平台. 它的各种工具可以无缝地协同工作,支持整个测试过程,从应用程序攻击面的初始映射和分析,到查找和利用安全漏洞. ...