Mocosh
Language:

What is Mocosh.DatasetManager?

Mocosh.DatasetManager is .NET library. It has the objects for working with DataSet objects.

Why is difficult to work with DataSet objects?

The DataSet object can have many tables which can have the relations with each other. We can fill very simply the data from database to DataSet. For that we can disable the checkup of reference integrity:

MyDataSet.EnforceConstraints = false;
....
MyDataSet.EnforceConstraints = true;

Also, DataSet objects which can be created in Visual Studio 2005 and Visual Studio 2008 have the relations without the reference integrity checkup.

After filling, we can modify the data in DataSet. We can insert, update or delete rows. For saving these changes to database we should use the the objects DataAdapter or the objects TableAdapter (which can be generated in VS 2005/2008). It difficult process.

For example:

We have the DataSet with two tables.

Tables schema

Let us assume that these tables have the inserted, modified and deleted data. We will try to save these changes to database. We will use these adapters by following order:

RegionDataAdapter.Update(MyDataset);
TerritoriesDataAdapter.Update(MyDataset);

The RegionDataAdapter.Update method should raise an exception because the Region table of DataSet has the deleted rows. The deleting these rows in database is impossible because they are linked with rows of Territories table.

We will try to use these adapters by following order:

TerritoriesDataAdapter.Update(MyDataset);
RegionDataAdapter.Update(MyDataset);

The TerritoriesDataAdapter.Update method should raise an exception because the Territories table of DataSet has the inserted rows. The inserting these rows is impossible into table of database because they are linked with rows of Region table.

We should use the following algorithm for saving the data to database:

DataTable t = MyDataset.Region.GetChanges(DataRowState.Added | DataRowState.Modified);
RegionDataAdapter.Update(t);
TerritoriesDataAdapter.Update(MyDataset);
t = MyDataset.Region.GetChanges(DataRowState.Deleted);
RegionDataAdapter.Update(t);
MyDataset.AcceptChanges();

This process doesn't use all tables of DataSet because it uses the copies of tables which have only inserted or deleted rows. If they have the identity columns then these columns should get data within inserting. Therefore we should copy these data to original tables of DataSet.

If the DataSet has a lot of tables with relations then the updating of this DataSet is very difficult. Especially if the tables have the identity columns or they have cyclic relations or relations with itself.

What can do the Mocosh.DatasetManager?

The library Mocosh.DatasetManager has the objects for working with DataSet objects. The class DatasetManager can fill and update all tables of DataSet object. If you will use this library then your source code which works with database will be more small. In following example we can look how this object saves the data from tables Territories and Region to database:

using Mocosh.Data;

DataAdapterInfo adapters = new DataAdapterInfo []
{
new DataAdapterInfo(TerritoriesDataAdapter),
new DataAdapterInfo(RegionDataAdapter)
};
DatasetManager manager = new DatasetManager(MyDataset, adapters);
manager.Update();