Validating DataSet with Validation Application Block

Topics: Building and extending application blocks, Validation Application Block
Mar 3, 2009 at 10:40 AM

I have implemented a business object class using a dataset as a private field for storing child data. For example consider an Order class with OrderDetails implemented as a private field of type DataSet (e.g. Private DataSet ordDet). The private dataset is exposed through a Public Property Getter and Internal Property Setter so that the actual dataset (OrderDetail) can only be assigned by its respective business logic controller class (while loading an Order) and not by UI developers working with the business object.

I was trying to implement object level validation for the Order object using Validation Application Block. The entire exercise was good with the Order master fields, using EAB provided validators as well as implementing custom validators and using validator attributes on respective properties of the business object. Windows Forms UI integration was also done and validation/error providers were working correctly providing a great UI experience. However, I got stuck while determining how to validate the OrderDetail data that is basically a DataSet type field of the business object bound to a DataGridView control

Has anybody tried validating a dataset (different fields in the datatable) using Enterprise Library Validation Application block. My validation objectives are

1. Windows Forms integrated validation of fields, so that input is validated at ColumnChanging event.

2. Reuse the same code for RowChanging event so that both the events are captured

3. Ability to execute all field/row level validations from a single call to the single Validation facade (Validation.Validate) that will validate the Order master header fields as well as the child dataset (OrderDetail).

4. Encapsulate validation logic from UI layer, the UI developers should not implement validation (data or business rule validation) logic, rather, the validation should be made available from the business logic layer components. So that rules out writing raw validation code in ColumnChanging or RowChanging event.

I have achieved some headway by implementing a separate custom validator at the business object level (using the Business Class itself as Validation target). This technique supplies the complete business object as a parameter to the DoValidate implementation. Extracting the child dataset and validating the complete dataset (scanning each row/col) was then a piece of cake and since I had used a Class level custom validtor, the entire validation (order fields and orderdetail dataset) could be done successfully through a single Validation.Validate call in the Save button click. Though that will reasonably protect the sanctity of the data, however, that will fire only when the user clicks the OK button and by that time he might have entered 50 lines of Order detail and this approach will then cause much frustration.

I would ideally like the user to get alerted by the ErrorProvider as soon as a column value is invalid, though a final comprehensive validation of the complete dataset will take place later.

I hope my objectives are clear. If anybody has a better idea please provide.





Mar 4, 2009 at 2:19 AM
See if this thread helps...

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.