logo
  • 教程列表
  • SO官方文档
  • Code First DataAnnotations
    • 列属性
    • 必需属性
    • MaxLength 和 MinLength 属性
    • DatabaseGenerated 属性
    • ForeignKey(字符串)属性
    • InverseProperty(字符串)属性
    • ComplexType 属性
    • 关键属性
    • 范围(minmax)属性
    • NotMapped 属性
    • 表属性
    • 索引属性
    • StringLength(int) 属性
    • 时间戳属性
    • ConcurrencyCheck 属性
  1. StackOverflow 文档
  2. Entity Framework 教程
  3. Code First DataAnnotations
  4. 必需属性

必需属性

Created: November-22, 2018

应用于域类的属性时,数据库将创建 NOT NULL 列。

using System.ComponentModel.DataAnnotations;

public class Person
{
    public int PersonID { get; set; }
    
    [Required]
    public string PersonName { get; set; }    
}

生成的列具有 NOT NULL 约束:

StackOverflow 文档

注意: 它也可以与 asp.net-mvc 一起用作验证属性。

  • MaxLength 和 MinLength 属性
  • 列属性

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明