Validate Typed DataSet

Topics: Validation Application Block
Aug 6, 2009 at 5:31 PM


Is it possible to validate a typed dataset? how?

Aug 7, 2009 at 6:57 AM
Edited Aug 7, 2009 at 8:42 AM


I think that would be possible since the typed dataset generates code which contains the properties that can be validated. Let say, you have a DataSet called "CustomerDataSet", a DataTable called "CustomerDataTable" and the rows of that datatable is "CustomerDataTableRow".

In your config:

  1. Add the type CustomerDataTableRow and add the validation for the properties of that row.
  2. Add the type CustomerDataTable, add the "Rows" property and add to it a Object Collection Validator, with the type of CustomerDataTableRow.
  3. Add the type CustomerDataSet, add the CustomerDataTable property and add Object Validator, the specify the rule set.
  4. Add the validation code:

Something like this:

CustomerDataSet ds = new CustomerDataSet();
ds.CustomerDataTable.AddCustomerDataTableRow("", "", "");
ValidationResults res = Validation.Validate<CustomerDataSet>(ds, "Rule Set");
But I doubt that this would work using the validator attributes, since the class is auto-generated. A change in the typed dataset will 
cause the code to be regenerated thus erasing the attributes. so i think it would not be possible in that approach. 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.