|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWhen you work with relational data you often have to work with Even if a database is properly designed, you can encounter the following major problems when using
BackgroundThere were a few articles on this problem, but I couldn't find an elegant and easy to use solution. So, I decided to create some kind of a component - a base class, which is easy to use, and which presents a solution to this problem. The ideas given in other articles were quiet OK, but they had some errors:
The next stepThe solution is simple. I've generated a class, which has a connection string and a AutoIncrementThe idea is to modify the
This solves the problem of AutoIncrement fields. If the parent field's AutoIncrement values are updated, this change is reflected in all the child foreign keys. Order of updateI found an article (possibly on CodeProject) where someone was complaining about the update. The problem is that the update-order cannot be arbitrary. First the parent table must be updated, then the child. So, either you keep track of the relationships, or you create an algorithm which examines the correct order of update. This code was checked with the The easiest solution:
So upon initialization, all the SQL queries and also the update order is calculated. I've finally added some functions:
There is also a function to define filters for the fill (for the query). Also, a property Using the code// init and fill
ds1 = new Dataset1();
ba1 = new BaseAccessor(
System.Configuration.ConfigurationSettings.AppSettings["ConnStr"], ds1);
ba1.AddFilter(ds1.Orders, "uid = @i_a", new object[] {55});
ba1.AddFilter(ds1.OrderedItems, "orderUid = @i_a", new object[] {55});
ba1.Fill();
// do here any inserts
// ...
// update
ba1.Update();
Points of interestThis class can be used as a base class for data manipulations.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||