TryGetParentRow Method

Overview

The TryGetParentRow method navigates a relation from a child row to its parent row.

It returns true when a matching parent row is found, otherwise returns false and sets parentRow to null.

Declaration

/// <summary>
/// Tries to find a parent row for a given child row and relation.
/// By default, Deleted parent rows are ignored.
/// </summary>
/// <param name="dataSet">Data set</param>
/// <param name="relationName">Relation name</param>
/// <param name="childRow">Child row</param>
/// <param name="ignoreDeletedParents">If true, Deleted parent rows are ignored</param>
/// <param name="parentRow">Parent row if found</param>
/// <returns>True if found, otherwise false</returns>
public static bool TryGetParentRow(this IDataSet? dataSet, string? relationName, IDataRow? childRow, bool ignoreDeletedParents, out IDataRow? parentRow)

Namespace and Assembly

Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll

Behavior

Usage Example

IDataSet dataSet = DataSetFactory.CreateDataSet();

IDataTable customers = dataSet.AddNewTable("Customers");
customers.AddColumn("Id", DataTypeNames.INT32, false, true);
customers.AddColumn("Name", DataTypeNames.STRING);

IDataTable orders = dataSet.AddNewTable("Orders");
orders.AddColumn("OrderId", DataTypeNames.INT32, false, true);
orders.AddColumn("CustomerId", DataTypeNames.INT32, false, false);
orders.AddColumn("Status", DataTypeNames.STRING);

dataSet.AddRelation(
"CustomerOrders",
"Customers",
new List<string> { "Id" },
"Orders",
new List<string> { "CustomerId" });

IDataRow c1 = customers.AddNewRow();
c1["Id"] = 1;
c1["Name"] = "Acme";
customers.AcceptChanges();

IDataRow o10 = orders.AddNewRow();
o10["OrderId"] = 10;
o10["CustomerId"] = 1;
o10["Status"] = "Open";
orders.AcceptChanges();

// Navigate: child -> parent
IDataRow? parentRow;
bool found = dataSet.TryGetParentRow("CustomerOrders", o10, ignoreDeletedParents: true, out parentRow);

// found == true, parentRow == c1

Notes

 

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.