Entity Framework Required Data Annotation
The Required attribute can be applied to a property to make it a required property in an entity class.
- EF will create a
NOT NULLcolumn in a database table for a property on which theRequiredattribute is applied. - If you save an entity without assigning a value to the
Requiredproperty, then EF 6 will throw theSystem.Data.Entity.Validation.DbEntityValidationExceptionexception.
public class Book { public int BookId { get; set; } [Required] public string Title { get; set; } }
ZZZ Projects