M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Understanding M# Validation

This tutorial explains key methods used to enforce data validation including entity properties and custom validation. As explained in tutorial Partial Classes and Business Logic two C# classes are generated for each entity type created in M#, in order to separate entity definition from the business logic. The same way M# separates basic data validation of properties from business logic validation by placing them in related entity classes and methods.

ValidateProperties()

M# implements all the basic data validation of properties in the “Entity” partial class in a method “ValidateProperties”. Data validation is specified while creating an entity e.g. required field, text pattern etc.

Validate()

All the custom business related validation of an entity is implemented in the “Logic” partial class by overriding “Validate” method. This method is called before saving or updating an entity instance. You should write all the business related validation rules in this method.