Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bizobj updates unchanged rows.
Message
 
À
03/09/2004 18:02:27
Max Fillmore
Essential Skills, Inc.
Lenexa, Kansas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00939368
Message ID:
00940048
Vues:
18
Max,

>I have a Parent-Child form very similar to the CustomerOrdersForm. When I insert, update, or delete any row of the child business object all rows are updated on SQL-Server. So if I have 20 child rows and I delete 3 of them I get 57 updates in the database. If I add 3 I get 63 updates. I know this is happening because the update triggers are firing.

I looked into this and as it turns out, if you have a business object's ForeignParentKeyField property set, the business object's PopulateKeyField() method is inadvertently setting the foreign parent key field of all rows in the DataTable. That's because the code in PopulateKeyField() is checking the following:
row[keyField] != keyValue
This code was intended to check if the values were different, but since both the row column and the keyValue parameter are of type object, the equality test is checking if they are referencing the same object rather than testing if they have the same value. The check should have been:
!keyValue.Equals(row[keyField])
For now, you can get around this problem by overriding your ABusinessObject's PopulateKeyField() method as shown here:
protected override void PopulateKeyField(string keyField, object keyValue, 
	string tableName)
{
	System.Data.DataTable dt = this.GetCurrentDataSet().Tables[tableName];
	foreach (System.Data.DataRow row in dt.Rows)
	{
		if (row[keyField] == System.DBNull.Value || !keyValue.Equals(row[keyField]))
		{
			row[keyField] = keyValue;
		}
	}
}
I'll add this to our "Known Issues" page and give you credit for finding this in the next version of the What's New Guide.

Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform