CopyToPoco Method
The CopyToPoco method copies values from an IDataRow into an existing
Plain Old CLR Object (POCO) instance.
Property matching between the data row and the POCO is performed in a
case-insensitive manner.
This method is typically used when applying a POCO DataSet changeset back to domain or persistence entities, such as Entity Framework Core tracked entities. Only values present in the data row are applied; missing fields are ignored.
/// <summary>
/// Copies values from a data row into an existing POCO instance.
/// Matching between property names and row keys is case-insensitive.
/// </summary>
/// <typeparam name="T">POCO type.</typeparam>
/// <param name="dataRow">Source data row.</param>
/// <param name="pocoInstance">Target POCO instance.</param>
public static void CopyToPoco<T>(this IDataRow? dataRow, T? pocoInstance)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
null, the property is set to null when possible.Convert.ChangeTypeNullable<T>Nullable<Enum>Guid and Nullable<Guid>DateTime and Nullable<DateTime> (round-trip invariant parsing)Assume that there are IEmploymentType interface and EmploymentType class which implements it:
public interface IEmploymentType
{
int Id { get; set; }
string? Code { get; set; }
string? Description { get; set; }
}
public class EmploymentType : IEmploymentType
{
public int Id { get; set; }
public string? Code { get; set; }
public string? Description { get; set; }
}
All properties assignment:
// 1. Create data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Create EmploymentType data table with one data row and data in it
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"] = "Part Time";
// 3. Create EmploymentType POCO
IEmploymentType employmentType = new EmploymentType();
// 4. Call CopyToPoco method and observe that all properties of employmentType instance are assigned
employmentTypeDataRow.CopyToPoco(employmentType);
Partial properties assignment:
// 1. Create data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Create EmploymentType data table with one data row and data in it
IDataTable employmentTypeDataTable = dataSet.AddNewTable("EmploymentType");
employmentTypeDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeDataTable.AddColumn("Code", DataTypeNames.STRING);
IDataRow employmentTypeDataRow = employmentTypeDataTable.AddNewRow();
employmentTypeDataRow["Id"] = 1;
employmentTypeDataRow["Code"] = "ET01";
// 3. Create EmploymentType POCO
IEmploymentType employmentType = new EmploymentType();
// 4. Call CopyToPoco method and observe that all properties of employmentType instance are assigned except Description
employmentTypeDataRow.CopyToPoco(employmentType);
Table of Content POCO DataSet DataRow 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.