Required Attribute in Entity Framework

The Entity Framework (EF) uses the Required attribute to generate the NOT NULL columns.

Required Attribute in Entity Framework
Required Attribute in Entity Framework

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

References

  1. RequiredAttribute Class

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top