views:

286

answers:

0

I am running into a problem when setting the UpdateBatchSize property to a number > 1 on my data adapter. I only get an error when I have a very specific type of DataRelationship on the table. Consider:

Table JobProductColorSize 
Columns:
Id : long //is a primary key
ParentAssemblyId : long?

Therefore I have a DataRelation created like so:

DataRelation rel = new DataRelation("FK_JobProductColorSize_Id__JobProductColorSize_ParentAssemblyId", Id, ParentAssemblyId, true);

When I call Update on my data adapter I get:

 ---> System.Data.InvalidConstraintException: ForeignKeyConstraint FK_JobProductColorSize_Id__JobProductColorSize_ParentAssemblyId requires the child key values (-12) to exist in the parent table.
   at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)

Hopefully I have made it clear of my problem. This only gets raised when I am using batching and only for relationships where the parent and child columns belong to the same table. I should point out there are many other data relations setup for this table and those work fine no matter the batching size. I would hate to disable batching because it is a pretty big difference in performance on large datasets.