Hello,
when I establish a master-child relation I set the ParentRelation property of the child PgSqlDataTable.
Afaik there is no property that relates from the Parent to the Child. It is only set from the Child to the Parent.
Is there a way I can iterate through all Childs that were set for a Parent table?
E.g. 3 tables
table1 is parent table of table2 and table3.
Now I want to list all the childs like this:
ListChilds(PgSqlDataTable table)
{
}
should output: table2 and table3
Master Detail Relation. Get all Child Tables
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Master Detail Relation. Get all Child Tables
PgSqlDataTable does not know if it has children. PgSqlDataTable knows only if it has a parent table.
However, you can use PgSqlDatSet. PgSqlDatSet contains tables and relations. For example, suppose you have table1 which is a parent of table2 and table3. If all these tables are created in PgSqlDataSet, and the corresponding relations are created, you can use the Relations collection. Check the ParentTable property for each of the Relations element. If it is equal to table1, you can get a value of the ChildTable property. After enumerating all the collection, you can get all the child tables of your table.
The code can look like the following:
However, you can use PgSqlDatSet. PgSqlDatSet contains tables and relations. For example, suppose you have table1 which is a parent of table2 and table3. If all these tables are created in PgSqlDataSet, and the corresponding relations are created, you can use the Relations collection. Check the ParentTable property for each of the Relations element. If it is equal to table1, you can get a value of the ChildTable property. After enumerating all the collection, you can get all the child tables of your table.
The code can look like the following:
Code: Select all
List<PgSqlDataTable> children = new List<PgSqlDataTable>();
foreach(DataRelation relation in pgSqlDataSet1.Relations)
{
if (relation.ParentTable == pgSqlDataSet1.Tables["table1"]) children.Add((PgSqlDataTable)relation.ChildTable);
}
Re: Master Detail Relation. Get all Child Tables
Thanks, that works!