The Entity Framework (EF) uses the Required
attribute to generate the NOT NULL columns.
1 2 3 4 5 6 7 8 9 10 | public class Employee { public int EmployeeID { get; set; } [Required] public string Name { get; set; } public string Address { get; set; } } |
In the above example, we decorate the Name
property with Required
Attribute. This will create the Name column as Not Null
in the database. Without the Required attribute, all string properties are mapped to NULLABLE
columns ( Example Address in the above model)
ASP.NET MVC also uses this attribute to Validate the model in the User interface