ContainsRelation Method
The ContainsRelation method checks whether IDataSet.Relations contains a relation with the specified name.
It is typically used to guard code that depends on a relation existing (navigation, validation, diagnostics). This method does not validate relation correctness (tables / columns may still be missing); it only checks the presence of relation metadata.
/// <summary>
/// Checks whether data set contains relation
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="relationName">Relation name</param>
/// <returns>True if data set contains relation, otherwise false</returns>
public static bool ContainsRelation(this IDataSet? dataSet, string relationName)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
false if dataSet is null.false if dataSet.Relations is null.
// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Create parent Department data table
IDataTable departmentDataTable = dataSet.AddNewTable("Department");
departmentDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentDataTable.AddColumn("Name", DataTypeNames.STRING);
// 3. Create child Employee data table with a foreign key column referencing the parent Department table
IDataTable employeeDataTable = dataSet.AddNewTable("Employee");
employeeDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeDataTable.AddColumn("DepartmentId", DataTypeNames.INT32, true, false, true);
// 4. Add a relation between the Department and Employee tables
List<string> parentColumnNames = new List<string>();
parentColumnNames.Add("Id");
List<string> childColumnNames = new List<string>();
childColumnNames.Add("DepartmentId");
dataSet.AddRelation("DepartmentEmployees", "Department", parentColumnNames, "Employee", childColumnNames);
// 5. Call ContainsRelation to verify that the relation was added successfully
bool departmentEmployeesRelationExists = dataSet.ContainsRelation("DepartmentEmployees"); // true
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.