DataSet with DataRelation combining child records from multiple parents into one

680 views Asked by At

Ive run into what seems to be kind of an odd issue with some legacy code. The code in question is creating a DataSet with 2 DataTables, and then defining the relationships between the tables before the data is used in a grid view (custom user control) - with child records grouped under the appropriate parent record. The relations seem to be setup correctly, with the ParentColumn and ChildColumn both set to columns with the matching values. However, if two other separate column values are the same between two parent, then all of the child records are showing underneath only one parent.

Dataset info

Resource table

| UserId | MemberId | FirstName | LastName | Email |
| 53C ... | C3A ........ | James ..... | Barnes .....| [email protected] |
| AE4 ... | 07A ......... | James ..... | Barnes .....| [email protected] |

Request table

| RequestId | OwnerId | MemberId |
| 1234 ........| 53C .......| C3A ......... |
| 2345 ........| AE4 .......| 07A ..........|
| 7689 ........| AE4 .......| 07A ......... |

In this scenario the rows from the Resource table are the parent records, and the rows from the Request table are the children. Based on this my expectation is that there would be one row underneath the record for 53C James Barnes, and 2 rows underneath AE4 James Barnes. When in actuality I am seeing 3 rows underneath 53C (I think) James Barnes. And the other James Barnes isn't listed.

Here is the setup for the DataRelation:

DataRelation resource_timesheet = new DataRelation(
                "relationName",
                ResourceTable.Columns[0],
                RequestTable.Columns[1],
                false);

Since the parent/child value columns are being referenced directly I would think that the column name would not matter (Maybe?).

Ive gone through a ton of articles that I could find here and elsewhere, and I have not found anything similar. Other than those cases where First and Last name in resource table match, everything else is working fine.

0

There are 0 answers