首页 > 其他 > 详细

Entity Framework Code-First(9.4):DataAnnotations - Required Attribute

时间:2016-07-05 17:04:04      阅读:199      评论:0      收藏:0      [点我收藏+]

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.

技术分享

Entity Framework Code-First(9.4):DataAnnotations - Required Attribute

原文:http://www.cnblogs.com/purplefox2008/p/5644138.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!