7.4 数据注解属性--Required
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.
如果真苦,你哪有时间喊累。如果真惨,你哪有时间觉得丢脸。因为承受得还不够,所以你才有时间抱怨。人生总有太多的无奈和遗憾,因为这就是生活。

浙公网安备 33010602011771号