DataRelation Members
Data relation defines how two tables, parent and child, are related to each other in a data set. It specifies which columns from the parent table match with which columns from the child table. This information is essential for navigating between related rows, enforcing referential integrity, and enabling features like cascading deletes or updates.
Columns that participate in a relation are usually key columns. The parent columns typically hold primary key values, while the child columns hold foreign key values that reference the parent rows.
public class DataRelation : IDataRelation
{
public List<string> ChildColumnNames { get; set; }
public string ChildTableName{ get; set; }
public string? DisplayField { get; set; }
public List<string> ParentColumnNames { get; set; }
public string ParentTableName { get; set; }
public string RelationName { get; set; }
}
Contract: IDataRelation interface in PocoDataSet.IData library
Implementation: DataRelation class in PocoDataSet.Data library
All properties are required to define a relation, except for DisplayField, which is optional and intended for presentation scenarios.
ChildColumnNames -
Column names from the child table that participate in the relation.
These columns usually hold foreign key values that reference the parent row.
ChildTableName -
The name of the child table, which contains rows whose foreign key values point to rows in the parent table.
DisplayField - Optional display field name for the relation.
This property can be used by UI helpers, lookup editors, or custom code to decide which column from the parent table should be shown to users.
ParentColumnNames -
Column names from the parent table that participate in the relation.
These columns are matched against the child columns at the same positions in ChildColumnNames.
ParentTableName -
The name of the parent table, which contains rows whose primary key values point to rows in the chald table.
RelationName -
Identifier used by relation-based extension methods, such as GetChildRows, TryGetParentRow, and ContainsRelation.
Single-column relation: Department.Id -> Employee.DepartmentId
IDataRelation relation = new DataRelation();
relation.RelationName = "Department_Employee";
relation.ParentTableName = "Department";
relation.ParentColumnNames = new List<string> { "Id" };
relation.ChildTableName = "Employee";
relation.ChildColumnNames = new List<string> { "DepartmentId" };
Composite relation: Shipment(OrderId, CompanyId) -> ShipmentLine(OrderId, CompanyId)
IDataRelation compositeRelation = new DataRelation();
compositeRelation.RelationName = "Shipment_ShipmentLine";
compositeRelation.ParentTableName = "Shipment";
compositeRelation.ParentColumnNames = new List<string> { "OrderId", "CompanyId" };
compositeRelation.ChildTableName = "ShipmentLine";
compositeRelation.ChildColumnNames = new List<string> { "OrderId", "CompanyId" };
Table of Content POCO DataSet API References POCO DataSet Types
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.