EnsureExistingRowsHaveColumn Method
The EnsureExistingRowsHaveColumn helper ensures that every existing row internal value dictionary contains an entry for a newly added column.
This is important when schema evolves (new columns are introduced) while rows already exist, because row accessors often assume that the key exists in the row underlying storage.
/// <summary>
/// Ensures that existing rows have column
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="columnName">column name</param>
static void EnsureExistingRowsHaveColumn(this IDataTable? dataTable, string columnName)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns immediately.dataTable.Rows.PocoDataSet.Data.DataRow type (so the method can safely access ValuesJson and OriginalValuesJson).columnName key is missing in ValuesJson, adds it with a null value.HasOriginalValues), also ensures the key exists in OriginalValuesJson.
// Typical usage is indirect:
// When a new column is added to a table that already has rows,
// the table/schema code should backfill rows with the new key.
using PocoDataSet.Data;
DataTable table = new DataTable();
table.TableName = "Employee";
table.AddColumn("Id", "Int32", isNullable: false, isPrimaryKey: true);
// Add a loaded row that (initially) only contains "Id"
var row = DataRowExtensions.CreateRowFromColumnsWithDefaultValues(table.Columns);
row["Id"] = 1;
table.AddLoadedRow(row);
// Later, schema evolves and you add a new column.
table.AddColumn("NickName", "String", isNullable: true);
// The table should ensure existing rows contain "NickName" = null,
// so row["NickName"] access is safe.
In your current source, this method is not public (it is an internal implementation helper inside DataTableExtensions).
If you expose schema mutation publicly (adding columns after data is loaded), keeping row dictionaries aligned avoids KeyNotFound-style issues and keeps original-value tracking consistent.
Table of Content POCO DataSet DataTable Extensions Group DataTable 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.