Mariusk,
The sample is rather simple and just gives you an idea of how validation works.
Obviously, you can always add complexity to it.
The validation on the sample is meant to happen to existing records in case you modify them with invalid data.
i.e. load one of the records and delete the FirstName value; as soon as you tab off the field, the validation will occur and complain about the problem (null value).
If you want to avoid the exception when you call SaveChanges on a newly created entity that hasn't had its values assigned, simply add some checking before save:
public void Save()
{
var result = _mgr.VerifierEngine.Execute(_currentEmployee);
if (!result.HasErrors) {
_mgr.SaveChanges();
} else {
MessageBox.Show(result.Errors.First().Message);
}
}
Notice that now the SaveChanges call won't occur unless all entities to be saved conform with validation rules. Also, if you navigate among the entities, you will notice that the required field in the new entity (i.e. First and LastName) will have the exclamation mark.