I am trying to merge two DataTable
s - one representing current data, and one representing proposed insertions to that data.
These tables have the same schema, both with a simple, user-provided primary key string.
What I'd like is, if the a proposed insertion row has a key that is already present in the current data, an error should be thrown. However, the proposed addition just gets merged as a proposed alteration to the existing row, which is not what I want.
My current code is something along the lines of
currentData.EnforceConstraints = false;
currentData.Merge(additions);
currentData.EnforceConstraints = true;
where I'm actually merging whole DataSet
s, not just DataTable
s. I was hoping to get an error on the EnforceConstraints = true
line, but I don't.
I also tried using diffgrams, but had the same problem - duplicate insertions get treated as modifications.
Is there a way to merge a set of insertions into a DataSet
and have duplicate PKs be treated as an error rather than an update?
Similarly, since modified DataRow
s remember their original values, I'd hope that merging a modified row whose original values don't match the target row's current values would throw an exception too.