ToDetachedList Method
The ToDetachedList extension method converts all rows of data table
into a list of detached interface objects.
Each returned object represents a snapshot of the row values at the moment the method is called.
Detached objects are not connected to the data table after creation.
Snapshot proxy properties are read-only. Attempting to assign to a property throws NotSupportedException. Reading a property returns the captured value,
and subsequent changes to the data table are not reflected in the detached objects.
/// <summary>
/// Returns observable data table as a detached list
/// </summary>
/// <typeparam name="TInterface">The interface type describing the table's row contract.</typeparam>
/// <param name="observableDataTable">Observable data table</param>
/// <returns>Observable data as a detached list</returns>
public static TInterface[] ToDetachedList<TInterface>(this IObservableDataTable? observableDataTable) where TInterface : class
/// <summary>
/// Returns observable data table as a detached list
/// </summary>
/// <typeparam name="TInterface">The interface type describing the table's row contract.</typeparam>
/// <param name="observableDataTable">Observable data table</param>
/// <param name="nameMap">Name map</param>
/// <returns>Observable data as a detached list</returns>
public static TInterface[] ToDetachedList<TInterface>(this IObservableDataTable? observableDataTable, IDictionary<string, string> nameMap) where TInterface : class
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
dataTable is null.Assuming that there is an interface IEmploymentType, which defines employment type functionality:
/// <summary>
// Defines employment type functionality
/// </summary>
public interface IEmploymentType
{
int Id { get; set; }
string Code { get; set; }
string? Description { get; set; }
}
// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();
// 2. Create Department observable table with row
IObservableDataTable employmentTypeObservableDataTable = observableDataSet.AddNewTable("EmploymentType");
employmentTypeObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
employmentTypeObservableDataTable.AddColumn("Code", DataTypeNames.STRING);
employmentTypeObservableDataTable.AddColumn("Description", DataTypeNames.STRING);
IObservableDataRow employmentTypeObservableDataRow1 = employmentTypeObservableDataTable.AddNewRow();
employmentTypeObservableDataRow1["Id"] = 1;
employmentTypeObservableDataRow1["Code"] = "ET01";
employmentTypeObservableDataRow1["Description"] = "Part Time";
// 4. Call ToDetachedList method to get an list of snapshot (read-only) proxies
List<IEmploymentType> employmentTypes = employmentTypeObservableDataTable.ToDetachedList<IEmploymentType>();
// 4. Verify that employment type is detached (read only) by attempting to modify a property
// This line throws NotSupportedException
employmentTypes[0].Code = "ET99"
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.