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

  • 關於本站
  • 免責聲明