Navigating relationships between tables

  • Thread starter Thread starter Matt Burland
  • Start date Start date
M

Matt Burland

With databinding you are allowed to use something like this:

new Binding("Text",myDS,"MyRel.MyChildField")

Where you use this .(dot) notation to navigate from the main table down to a
child table, but this seems to be the only place you can use this rather
handy and compact syntax. For example, I can't do this

Object obj = myDataRow["MyRel.MyChildField"];

Instead I have to do this:

DataRow[] children = myDataRow.GetChildRows["MyRel"];
Object obj = children[0]["MyChildField"];

Which is ugly and cumbersome especially when your tables have a 1-to-1
relationship.
Is there a more compact and elegant way to get at data in a child row given
the related row in the parent table that I'm missing here?
 
With databinding you are allowed to use something like this:

new Binding("Text",myDS,"MyRel.MyChildField")

Where you use this .(dot) notation to navigate from the main table down to a
child table, but this seems to be the only place you can use this rather
handy and compact syntax. For example, I can't do this

Object obj = myDataRow["MyRel.MyChildField"];

Instead I have to do this:

DataRow[] children = myDataRow.GetChildRows["MyRel"];
Object obj = children[0]["MyChildField"];

Which is ugly and cumbersome especially when your tables have a 1-to-1
relationship.
Is there a more compact and elegant way to get at data in a child row given
the related row in the parent table that I'm missing here?

Not really.
The only way is when you create a typed dataset.
If you have relations in the dataset, you get some usable methods for
querying children and parents such as "Prodcut.GetOrders()"
 
Back
Top