AddNewTableFromPocoInterface Method
The AddNewTableFromPocoInterface method adds a new IDataTable to an
IDataSet and builds the table schema by reflecting over a POCO interface type.
It creates the table, assigns the table name, adds it to the data set, and then calls
AddColumnsFromInterface(Type) to populate column metadata based on the interface properties.
This method is primarily intended for fast in-memory schema creation in scenarios such as dynamic UI generation, unit tests, metadata-driven APIs, and client-side composition of data sets.
There are several overloads of the AddNewTableFromPocoInterface method:
/// <summary>
/// Adds new table from POCO interface to data set
/// Table name will be equal to interface name.
/// </summary>
/// <typeparam name="TInterface">Interface type</typeparam>
/// <param name="dataSet">Data set</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTableFromPocoInterface
/// <summary>
/// Adds new table from POCO interface to data set. Use this overload when contract requires a specific name.
/// </summary>
/// <typeparam name="TInterface">Interface type</typeparam>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTableFromPocoInterface
/// <summary>
/// Adds new table from POCO interface to data set
/// Table name will be equal to interface name.
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="interfaceType">Interface type</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTableFromPocoInterface(this IDataSet? dataSet, Type interfaceType)
/// <summary>
/// Adds new table from POCO interface to data set
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="tableName">Table name</param>
/// <param name="interfaceType">Interface type</param>
/// <returns>New table</returns>
/// <exception cref="KeyDuplicationException">Exception is thrown if dataset contains a table with specified name already</exception>
public static IDataTable AddNewTableFromPocoInterface(this IDataSet? dataSet, string tableName, Type interfaceType)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
Assume there is an interface that describes the schema of an EmploymentType entity:
/// <summary>
/// Defines employment type functionality
/// </summary>
internal interface IEmploymentType
{
string Code { get; set; }
string? Description { get; set; }
int Id { get; set; }
}
1. You can create a table with name inferred from interface name:
// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Call AddNewTableFromPocoInterface to add a new table named "IEmploymentType" with schema from IEmploymentType interface
IDataTable employmentTypeDataTable = dataSet.AddNewTableFromPocoInterface<IEmploymentType>();
1. You can create a table with specified name:
// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Call AddNewTableFromPocoInterface to add a new table named "EmploymentType" with schema from IEmploymentType interface
IDataTable employmentTypeDataTable = dataSet.AddNewTableFromPocoInterface<IEmploymentType>("EmploymentType");
1. You can create a table with name inferred from interface type:
// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Call AddNewTableFromPocoInterface to add a new table named "IEmploymentType" with schema from IEmploymentType interface
IDataTable employmentTypeDataTable = dataSet.AddNewTableFromPocoInterface(typeof(IEmploymentType));
2. You can create a table with a specific name:
// 1. Create a new data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Call AddNewTableFromPocoInterface to add a new table named "EmploymentType" with schema from IEmploymentType interface
IDataTable employmentTypeDataTable = dataSet.AddNewTableFromPocoInterface("EmploymentType", typeof(IEmploymentType));
AddColumnsFromInterface.
Table of Content POCO DataSet DataSet 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.