DoPostSaveMerge Method

Overview

The DoPostSaveMerge method applies a post-save server response (a changeset) to the current data set.

A typical use case is applying server-assigned values such as identity primary keys and concurrency tokens (for example, RowVersion) back to newly added rows on the client.

Declaration

/// <summary>
/// Dose PostSave 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 DoPostSaveMerge(this IDataSet? currentDataSet, IDataSet changesetDataSet, IMergeOptions mergeOptions)

Namespace and Assembly

Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll

Behavior

Usage Example

// CURRENT: client-side state (a new Department row exists but has no server Id yet).
IDataSet currentDataSet = DataSetFactory.CreateDataSet();

IDataTable currentDepartment = currentDataSet.AddNewTable("Department");
currentDepartment.AddColumn("Id", DataTypeNames.INT32);
currentDepartment.AddColumn("Name", DataTypeNames.STRING);
currentDepartment.AddColumn("RowVersion", DataTypeNames.BINARY);

IDataRow newRow = currentDepartment.AddNewRow();
newRow["Name"] = "Engineering";

// When a new row is created, POCO DataSet assigns a __ClientKey to correlate with server replies.
Guid clientKey = newRow.GetDataFieldValue<Guid>(SpecialColumnNames.CLIENT_KEY);

// POST-SAVE (server response): same row, now with Id and RowVersion assigned.
IDataSet postSaveDataSet = DataSetFactory.CreateDataSet();

IDataTable postSaveDepartment = postSaveDataSet.AddNewTable("Department");
postSaveDepartment.AddColumn("Id", DataTypeNames.INT32);
postSaveDepartment.AddColumn("Name", DataTypeNames.STRING);
postSaveDepartment.AddColumn("RowVersion", DataTypeNames.BINARY);

IDataRow savedRow = postSaveDepartment.AddNewRow();
savedRow["Id"] = 10;
savedRow["Name"] = "Engineering";
savedRow["RowVersion"] = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 };
savedRow[SpecialColumnNames.CLIENT_KEY] = clientKey;

IMergeOptions options = new MergeOptions();

// Apply post-save response to CURRENT.
currentDataSet.DoPostSaveMerge(postSaveDataSet, options);

// After merge, CURRENT row contains server-assigned Id and RowVersion.
int id = currentDepartment.Rows[0].GetDataFieldValue<int>("Id"); // 10
byte[]? rv = currentDepartment.Rows[0].GetDataFieldValue<byte[]>("RowVersion"); // {1,0,0,0,0,0,0,0}

Notes

 

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 Code examples are provided under the MIT License.
Creative Commons Attribution 4.0 International License (CC BY 4.0).
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.