The DevForce Object mapper will, at your option, automatically generate verifiers that enforce constraints implicit in the column definitions of the backing database: e.g., it will create verifiers that enforce nullability, width, and so forth. Beyond that you must configure your own verifiers and DataConverters.
>> do I need to create a Verifier (say in the Employees.GetVerifiers? or is there a better suggestion) and a DataConverter like a NumericRangeConverter in the Form, myself?
Yes, you’re right on the money. In Employee.GetVerifiers() you would add, to the List of verifiers to be returned from the method, a verifier that would probably be a subclassed Int32RangeVerifier.
In the Form code, you would create the NumericRangeConverter. If you wished to configure the ControlBindingDescriptor from scratch, it would look something like this:
NumericRangeConverter converter = new NumericRangeConverter(typeof(int));
converter.MinValue = 12;
converter.MaxValue = 120;
ControlBindingDescriptor descriptor = new ControlBindingDescriptor(_ageTextBox, typeof(DomainModel.Employee), "Age", converter);
_employeesControlBindingManager.Descriptors.Add(descriptor);
Alternatively, you could set up your bindings using the ControlBindingManager designer, letting the designer generate all of the code for the databindings; then, in your form code, swap out the DataConverter used in the descriptor for the Age binding:
ControlBindingDescriptor descriptor =
_employeesControlBindingManager.Descriptors.Get(Employee.PathFor(e => e.Age));
descriptor.DataConverter = converter;
For the record, age would probably be actually be a calculated property based on a BirthDate, so that your actual constraints would be on the BirthDate.
|