If you want to change the validation logic later, you can do so in exactly one place by adding validation attributes to the model (in this example, the class).You won't have to worry about different parts of the application being inconsistent with how the rules are enforced — all validation logic will be defined in one place and used everywhere.It's generally not a good practice to compile hard dates in your models, so using the Range attribute and Date Time is discouraged.
It also ensures that you can't forget to validate something and inadvertently let bad data into the database.The Regular Expression attribute is used to limit what characters can be input. Code First ensures that the validation rules you specify on a model class are enforced before the application saves changes in the database.For example, the code below will throw a Db Entity Validation Exception exception when the Having validation rules automatically enforced by the .model, and you'll ensure that the validation rules are enforced any time a user attempts to create or edit a movie using the application. You can declaratively specify validation rules in one place (in the model class) and the rules are enforced everywhere in the application. This reduces the amount of code you need to write and makes the code you do write less error prone and easier to maintain. NET MVC and Entity Framework Code First is a great example of the DRY principle in action.