CreateChangeset Method
The CreateChangeset method creates a new data set, a "changeset", 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 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.
Changesets are typically used as input to data persistence layers, such as Entity Framework Core DbContext or SQL Server Data Adapter.
/// <summary>
/// Creates a "changeset" dataset that contains only rows in Added / Modified / Deleted states.
/// </summary>
/// <param name="currentObservableDataSet">Current observable data set</param>
/// <returns>Dataset containing changed rows</returns>
public static IDataSet? CreateChangeset(this IObservableDataSet? currentObservableDataSet)
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();
// 2. Create Department observable data table with one row in Unchanged state and one row in Added state
IObservableDataTable departmentObservableDataTable = observableDataSet.AddNewTable("Department");
departmentObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentObservableDataTable.AddColumn("Name", DataTypeNames.STRING);
IObservableDataRow departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 1;
departmentObservableDataRow["Name"] = "Reception";
departmentObservableDataRow.AcceptChanges();
departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 2;
departmentObservableDataRow["Name"] = "Emergency";
// 3. Create EmploymentType observable data table with one row in Unchanged state and one row in Modified state
IObservableDataTable employmentTypeObservableDataTable = observableDataSet.AddNewTable("EmploymentType");
employmentTypeObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeObservableDataTable.AddColumn("Code", DataTypeNames.STRING);
employmentTypeObservableDataTable.AddColumn("Description", DataTypeNames.STRING);
IObservableDataRow employmentTypeObservableDataRow = employmentTypeObservableDataTable.AddNewRow();
employmentTypeObservableDataRow["Id"] = 1;
employmentTypeObservableDataRow["Code"] = "ET01";
employmentTypeObservableDataRow["Description"] = "Full Time";
employmentTypeObservableDataRow.AcceptChanges();
employmentTypeObservableDataRow["Id"] = 2;
employmentTypeObservableDataRow["Code"] = "ET02";
employmentTypeObservableDataRow["Description"] = "Contract";
employmentTypeObservableDataRow.AcceptChanges();
employmentTypeObservableDataRow["Description"] = "Part Time";
// 4. Create Employee observa ble data table with one row in Unchanged state and one row in Deleted state
IObservableDataTable employeeObservableDataTable = observableDataSet.AddNewTable("Employee");
employeeObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeObservableDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeObservableDataTable.AddColumn("LastName", DataTypeNames.STRING);
IObservableDataRow employeeObservableDataRow = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow["Id"] = 1;
employeeObservableDataRow["FirstName"] = "Sara";
employeeObservableDataRow["LastName"] = "Gor";
employeeObservableDataTable.AcceptChanges();
employeeObservableDataRow = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow["Id"] = 2;
employeeObservableDataRow["FirstName"] = "Paul";
employeeObservableDataRow["LastName"] = "Murray";
employeeObservableDataTable.AcceptChanges();
employeeObservableDataRow.Delete();
// 5. Build a changeset that contains only changed rows
// - Department table will have one row with Id=2 in Added state
// - EmploymentType table will have one row with Id=2 in Modified state
// - Employee table will have one row with Id=2 in Deleted state
IDataSet? changeset = observableDataSet.CreateChangeset();
Table of Content POCO DataSet Observable Data Set 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.