Saturday, March 06, 2010

.NET typed dataset bug

When working with typed datasets having more than one table which acts as parent table (with primary keys) in a relationship, you are bound to get an exception.

Reason -
The moment first table in the dataset is populated, ALL constraints are enforced. This means there will be some parent tables which will not be populated, which will give rise to an exception.

You can't act smart and return all parent tables in one data set and populate them in one go using
DataAdapter.TableMappings, because this exception will be thrown the moment first table is mapped to dataset.

The only workaround I could think of was to do the following:

  1. Populate all parent tables in one method and ensure that this method is called before any other data operation or population method.
  2. In this method, set EnforceConstraints to false before starting data retrieval and set it back to true once the retrieval is complete.
Ideal behaviour - 
Only the constraints related to the populated datable should be activated.

This wasted loads and loads of my time. I hope it saves some of yours.

No comments: