none
How do you navigate one-to-one relationships in a dataset? RRS feed

  • Question

  • The following pertains to ADO.NET 2.0:

     

    You can use the DataRow's GetParentRow and GetChildRows methods to navigate between rows that are related as one-to-many or many-to-many, but how to you navigate between rows that are related as one-to-one? I've read David Sceppa's ADO.NET 2.0 book (2005 edition), and there's nothing in there about this.


    Does it just depend on how the columns from two tables are passed to the DataRelation class constructor? In other words, If the DataRelation object was created with a call like this (in VB)


    rel = New DataRelation("rlTable1Table2", Dataset1.Tables("Table1").Columns("ID"), Dataset1.Tables("Table2").Columns("ID"))


    then going from Table1 to Table2 requires GetChildRows, because Table1 has the column that was passed to the DataRelation constructor as the first argument? Likewise, going from Table2 to Table1 requires GetParentRow or GetParentRows, because Table2's column was the second column passed to the DataRelation constructor?


    Perhaps this is how it works when there are no pre-existing key constraints, or when there are primary key constraints on both columns or unique key constraints on both columns.

    Friday, June 13, 2008 1:16 AM

Answers

  • > You can use the DataRow's GetParentRow and GetChildRows methods to navigate between rows that are related as one-to-many or many-to-many, but how to you navigate between rows that are related as one-to-one?

     

    The same way.  If you know that the relationship is one-to-one, then you will know that GetChildRows will return only one row.

     

     

    Sunday, June 22, 2008 10:28 PM