DoRefreshMergePreservingLocalChanges Method
The DoRefreshMergePreservingLocalChanges method refreshes the current data set from a server snapshot while preserving local pending changes.
In this strategy, rows in Added, Modified, or Deleted state are never overwritten by refreshed values.
/// <summary>
/// Dose RefreshPreservingLocalChanges merge
/// </summary>
/// <param name="currentDataSet">Current data set</param>
/// <param name="refreshedDataSet">Refreshed data set</param>
/// <param name="mergeOptions">Merge options</param>
public static void DoRefreshMergePreservingLocalChanges(this IDataSet? currentDataSet, IDataSet refreshedDataSet, IMergeOptions mergeOptions)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
currentDataSet is null, the method returns without doing anything.Added, Modified, or Deleted state are preserved (the refreshed row does not overwrite them).
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable table = dataSet.AddNewTable("Department");
table.AddColumn("Id", DataTypeNames.INT32, isNullable: false, isPrimaryKey: true);
table.AddColumn("Name", DataTypeNames.STRING);
// CURRENT: one unchanged row
IDataRow currentRow = table.AddNewRow();
currentRow["Id"] = 1;
currentRow["Name"] = "Old";
dataSet.AcceptChanges(); // row becomes Unchanged
// The user deletes the row locally (local work must be preserved).
currentRow.Delete();
// REFRESHED: server snapshot still has Id=1.
IDataSet refreshed = DataSetFactory.CreateDataSet();
IDataTable rTable = refreshed.AddNewTable("Department");
rTable.AddColumn("Id", DataTypeNames.INT32, isNullable: false, isPrimaryKey: true);
rTable.AddColumn("Name", DataTypeNames.STRING);
IDataRow refreshedRow = rTable.AddNewRow();
refreshedRow["Id"] = 1;
refreshedRow["Name"] = "Server";
refreshed.AcceptChanges();
IMergeOptions options = new MergeOptions();
// Act: local delete should NOT be overwritten.
dataSet.DoRefreshMergePreservingLocalChanges(refreshed, options);
// CURRENT row stays Deleted (and Name is not overwritten).
Assert.Equal(DataRowState.Deleted, table.Rows[0].DataRowState);
DoRefreshMergeIfNoChangesExist.Table of Content POCO DataSet DataSet Members
Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the
Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate
credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness
or suitability of the information and are not responsible for any damages
resulting from its use.