Please consider the following situation:
- DataSet A contains the current set of data found in some data source.
- DataSet B contains future changes to the data found in A, which have not yet been applied to A.
Using .NET’s DataSet.Merge(DataSet) method, we can apply B to A, creating a new DataSet C, i.e. C = A.Merge(B).
The problem with the DataSet.Merge(DataSet) Merge method is that, for any row r which is flagged as Deleted in B, r will be flagged as Modified in C. Whilst, clearly, r in C should be flagged Deleted as well.
A solution which would work, but I find unappealing, is to manually enumerate across all Deleted rows in B, and use their identifier to find the same row in C, thereafter changing the RowState of that row in C to Deleted as well.
What would be the proper solution to the above problem?
I have been playing around with datasets and came up with the democode below (based on MSDN) to test some of the things you ask. (.net framework 4.0 VS2010)
What I find is that merge is void so when looking at your question we have A.Merge(B) and A is merged with B.
Normal merging (without the preserveChanges flag) makes B leading so when something is deleted in B and it was present in A it will also be deleted in the new A. If I read your question correctly this is the behaviour desired by you. (testoutput A)
If you have set the preservechanges flag to True than strange things start to happen, the deleted flag for example will be a modified in the new A. (testoutput B)
If you have the preservechnages flag set to true, set it to false. As far as I can tell the default behaviour is what you want and you that isn’t what you see. I suspect something else to be wrong, hope this helps you in the right direction
TestOutput A (preservechanges = false)
Test output B (with preservechanges to true)