原文: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. Linux服务器---配置nfs

    配置nfs NFS服务的主要配置文件为/etc/exports./etc/exports文件内容格式: <输出目录> 客户端(选项:访问权限,用户映射,其他) 1.输出目录 输出目录是指N ...

  2. Java中的ASCII码与Unicode码

    先上代码 后续更新 public class Unicode { public static void main(String[] args) { char ch1 = 'c'; char ch2 = ...

  3. EDK II之USB设备驱动程序的加载与运行

    本文简单介绍一下USB设备的驱动程序是如何匹配设备以及被加载的: 上文(UDK中USB总线驱动的实现框架)提到USB总线枚举设备的最后一步是调用gBS->ConnectController()去 ...

  4. php的serialize()函数和unserialize()函数

    适用情境:serialize()返回字符串,此字符串包含了表示value的字节流,可以存储于任何地方.这有利于存储或传递 PHP 的值,同时不丢失其类型和结构.比较有用的地方就是将数据存入数据库或记录 ...

  5. php 使用fileupload上传多张图片,压缩包

    test.php <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  6. mysql常用的操作命令

    在mysql中以半角分号;作为命令的结束符 查看当前系统包含的数据库:mysql> show databases [like ' ']; 从一个数据库切换到另一个:mysql>use ol ...

  7. RAFT实践

    1.  raft org 2. paper 3. animation 4. python examples Raft-python  这个不是很好用. simpleRaft Raft算法分析与理解  ...

  8. shell脚本一键安装nginx

    依赖包安装包放在一起, 直接执行这个脚本就行. #!/bin/bash #--------------------------------------------------------------- ...

  9. 【VNC】修改VNC分辨率大小

    [VNC]修改VNC分辨率大小 VNC的分辨率过小有可能导致图形化界面操作过程中遇到"确认键或取消键"无法点击,分辨率过高又可能导致低分辨率客户端显示器无法显示.本文给出两种调整V ...

  10. 计算多数的乘积(Python实现)

    1 # -*- coding: utf-8 -*- # sum_of_products.py # @author 0yst3r # @description 两数之积及多数之积 # @created ...