CreateChangeset Method

Overview

The CreateChangeset method creates a new data set that contains only the rows that have been changed in the current data set. A row is considered "changed" when its DataRowState is Added, Modified, or Deleted.

The returned data set (the "changeset") contains only the tables that have at least one changed row. Each included table is created with the same column metadata as the source table, and then the changed rows are copied into the changeset.

Declaration

/// <summary>
/// Creates a "delta changeset" dataset.
/// - Added rows: full row values (same as CreateChangeset).
/// - Modified rows: only primary key columns + __ClientKey (if present) + changed columns.
/// - Deleted rows: only primary key columns + __ClientKey (if present).
/// </summary>
/// <param name="dataSet">Data set.</param>
/// <returns>Delta changeset data set, or null if source is null</returns>
public static IDataSet? CreateChangeset(this IDataSet? dataSet)

Namespace and Assembly

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

Behavior

Usage Example

// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();

// 2. Create data table with one row in Added state
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);

IDataRow departmentDataRow = departmentDataTable.AddNewRow();
departmentDataRow["Id"] = 1;
departmentDataRow["Name"] = "Reception";

// 3. Create data table with one row in Modified state
IDataTable employmentTypeDataTable = dataSet.AddNewTable("EmploymentType");
employmentTypeDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeDataTable.AddColumn("Code", DataTypeNames.STRING);
employmentTypeDataTable.AddColumn("Description", DataTypeNames.STRING);

IDataRow employmentTypeDataRow = employmentTypeDataTable.AddNewRow();
employmentTypeDataRow["Id"] = 1;
employmentTypeDataRow["Code"] = "ET01";
employmentTypeDataRow["Description"] = "Full Time";
employmentTypeDataRow.AcceptChanges();
employmentTypeDataRow["Description"] = "Part Time";

// 4. Create data table with one row that will be deleted
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeDataTable.AddColumn("LastName", DataTypeNames.STRING);

IDataRow employeeDataRow = employeeDataTable.AddNewRow();
employeeDataRow["Id"] = 1;
employeeDataRow["FirstName"] = "Sara";
employeeDataRow["LastName"] = "Gor";
employeeDataTable.AcceptChanges();
employeeDataRow.Delete();

// 5. Build a changeset that contains only changed rows:
// - Department table: 1 Added row with both Id and Name fields
// - EmploymentType table: 1 Modified row with Id and changed Description field
// - Employee table: 1 Deleted row with only Id field
IDataSet? changeset = dataSet.CreateChangeset();

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 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.