CopyFromPoco Method
The CopyFromPoco method copies values from a POCO object into an IObservableDataRow by reading
all public instance properties that have a getter. Each readable property value is assigned to the data row
field with the same name as the property.
This method does not validate that the POCO structure matches the row schema. For predictable results, ensure that the row contains fields for the POCO properties (for example, by creating the table from an interface and creating the row from the table columns).
/// <summary>
/// Copies public readable POCO properties into an observable data row.
/// Matching between property names and existing row keys is case-insensitive.
/// </summary>
/// <typeparam name="T">POCO type</typeparam>
/// <param name="observableDataRow">Target observable data row</param>
/// <param name="pocoInstance">Source POCO instance</param>
public static void CopyFromPoco<T>(this IObservableDataRow? observableDataRow, T? pocoInstance)
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
Let’s assume there is an interface that defines the employment type:
internal interface IEmploymentType
{
string Code { get; set; }
string? Description { get; set; }
int Id { get; set; }
}
And a class that implements the interface:
internal class EmploymentType
{
public string Code { get; set; }
public string? Description { get; set; }
public int Id { get; set; }
}
Import data from an EmploymentType object into a row:
// 1. Create a new observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();
// 2. Create an empty data table from POCO interface and create a new row
IObservableDataTable employmentTypeObservableDataTable = observableDataSet.AddNewTableFromPocoInterface("EmploymentType", typeof(IEmploymentType));
IObservableDataRow employmentTypeDataRow = employmentTypeObservableDataTable.AddNewRow();
// 3. Create POCO object
EmploymentType employmentType = new EmploymentType();
employmentType.Id = 1;
employmentType.Code = "ET01";
employmentType.Description = "Full Time";
// 4. Copy values from POCO instance into the row
employmentTypeDataRow.CopyFromPoco<EmploymentType>(employmentType);
Table of Content POCO DataSet Observable Data Row 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.