zoukankan      html  css  js  c++  java
  • Entity Framework Code-First(9.4):DataAnnotations

    Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT NULL column in a database table for a property on which we apply Required attribute. Note that it can also be used with ASP.Net MVC as a validation attribute.

    Consider the following example.

    using System.ComponentModel.DataAnnotations;
        
    public class Student
    {
        public Student()
        { 
            
        }
        public int StudentID { get; set; }
         
        [Required]
        public string StudentName { get; set; }
            
    }

    As you can see in the above code, we have applied Required attribute to StudentName. So, Code First will create a NOT NULL StudentName column in the Student table as shown below.

    dataannotations required attribute

  • 相关阅读:
    封装
    面向对象的思想
    Arrays工具类
    二分查找
    选择排序
    冒泡排序
    对象数组
    二维数组
    一维数组
    循环语句注意事项
  • 原文地址:https://www.cnblogs.com/purplefox2008/p/5644138.html
Copyright © 2011-2022 走看看