Adding validations to entity classes
Validating data is the process of confirming that the values entered into data objects comply with the constraints in an object's schema, in addition to the rules established for your application. Validating data before you send updates to the underlying database is a good practice that reduces both errors and the potential number of round trips between an application and the database.
The Entity designer provides partial methods that enable users to extend the designer-generated code that runs during Inserts, Updates, and Deletes of complete entities and also during and after individual column changes.
These validation methods are all partial methods. Therefore, there is no overhead at all if you don't implement them because unimplemented partial methods are not compiled into IL.
You can implement a validation method in another partial class. In our example we can add the following method to the Program.cs
file:
public partial class Product { partial...