Required Attribute in EF Core

The EF Core uses Required attribute to generate NOT NULL columns.

Required Attribute in Entity Framework core
Required Attribute in Entity Framework Core

In the above example, the Name property is decorated 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