S
s.gregory
The problem is simple: Astonishingly, it seems that in an ADO.NET 2.0
dataset, adding new rows to a child table does not seem to immediately
reflect in any aggregate filter placed upon the parent table.
For simplicity I have written some code below for a simple .NET 2.0
winforms app and a very basic stongly typed dataset 'MyDataset'.
'MyDataset' has the following schema (of two simple tables and one
relationship between them):
Table1: 'ParentTable'
ID (System.Int32, AutoIncrement, Primary Key)
Name (System.String)
Table2: 'ChildTable'
GUID (System.Guid, Primary Key)
ParentTableID (System.Int32)
Relationship1: 'FK_ParentTable_ChildTable'
PK: [ParentTable].[ID]
FK: [ChildTable].[ParentTableID]
Both Relation and Foreign Key Constraint checked with cascading Update
and Deletes.
The Form just needs two Labels (Label1, Label2) and a Button (Button1)
and then you can paste the following into the code file:
After clicking the button, you should see that the first label shows 0
(i.e. the filter does not recognise the new child rows).
However, the second label correctly returns 2, but this is only
because table has been 'refreshed' with a merge.
Three questions:
1) Is this a bug or can anybody tell me if I am missing anything?
2) If it is a bug, is it a known bug with ADO.NET 2.0 (I have
previously had similar issues with 1.1, but I thought these were
supposed to have been fixed), or a is it a 'feature'?
3) Is there any elegent workaround to ensure the parent filter always
returns the correct result? ( i.e. a way to quickly refresh the
filter's/index's memory without resorting to repopulating the entire
parent table every time a child row is added).
Many Thanks,
Simon
dataset, adding new rows to a child table does not seem to immediately
reflect in any aggregate filter placed upon the parent table.
For simplicity I have written some code below for a simple .NET 2.0
winforms app and a very basic stongly typed dataset 'MyDataset'.
'MyDataset' has the following schema (of two simple tables and one
relationship between them):
Table1: 'ParentTable'
ID (System.Int32, AutoIncrement, Primary Key)
Name (System.String)
Table2: 'ChildTable'
GUID (System.Guid, Primary Key)
ParentTableID (System.Int32)
Relationship1: 'FK_ParentTable_ChildTable'
PK: [ParentTable].[ID]
FK: [ChildTable].[ParentTableID]
Both Relation and Foreign Key Constraint checked with cascading Update
and Deletes.
The Form just needs two Labels (Label1, Label2) and a Button (Button1)
and then you can paste the following into the code file:
Code:
Public Class Form1
Dim m_oDS As New MyDataset
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
FillParent()
FillChild()
' ================================================
' This should return 2 but it actaully returns 0
' ================================================
Label1.Text = CountRowsWithChildren()
' ================================================
' Re-Merging/Filling the Parent Table seems to
' cause the filter to 'refresh' and return 2
' - But this is NOT a very elegent work around!
' ================================================
FillParent()
Label2.Text = CountRowsWithChildren()
End Sub
Public Sub FillParent()
Dim oTB As New MyDataset.ParentTableDataTable
oTB.AddParentTableRow("Row 1")
oTB.AddParentTableRow("Row 2")
oTB.AcceptChanges() ' Curiously, the filter works correctly if
you comment this line out (i.e. When the ParentRow also has a RowState
of 'Added')
m_oDS.ParentTable.Merge(oTB, True)
End Sub
Public Sub FillChild()
m_oDS.ChildTable.AddChildTableRow(Guid.NewGuid,
m_oDS.ParentTable.FindByID(0))
m_oDS.ChildTable.AddChildTableRow(Guid.NewGuid,
m_oDS.ParentTable.FindByID(1))
End Sub
Public Function CountRowsWithChildren()
Return
m_oDS.ParentTable.Select("COUNT(CHILD(FK_ParentTable_ChildTable).
[ParentTableID]) > 0").GetLength(0)
End Function
End Class
After clicking the button, you should see that the first label shows 0
(i.e. the filter does not recognise the new child rows).
However, the second label correctly returns 2, but this is only
because table has been 'refreshed' with a merge.
Three questions:
1) Is this a bug or can anybody tell me if I am missing anything?
2) If it is a bug, is it a known bug with ADO.NET 2.0 (I have
previously had similar issues with 1.1, but I thought these were
supposed to have been fixed), or a is it a 'feature'?
3) Is there any elegent workaround to ensure the parent filter always
returns the correct result? ( i.e. a way to quickly refresh the
filter's/index's memory without resorting to repopulating the entire
parent table every time a child row is added).
Many Thanks,
Simon