I am using a LINQ to SQL datacontext which has a Sample entity and the Sample entity has a child entityset, Drums. I have written this code in the Sample partial class to handle adding new drums:
Partial Class Sample
Public Sub New(ByVal limsNumber As String, ByVal lotNumber As String, ByVal createDate As Date)
Me.New()
Me.LIMSNum = limsNumber
Me.LotNum = lotNumber
Me.DateReceived = createDate
End Sub
Public Sub AddDrum()
Me.Drums.Add(New Drum With {.DrumNum = Me.Drums.Count + 1})
End Sub
Public Sub AddDrum(ByVal palletNum As Integer, ByVal grossWeight As Integer, ByVal tareWeight As Integer)
AddDrum(New Drum With {.GrossWeight = grossWeight, .TareWeight = tareWeight, .PalletNum = palletNum})
End Sub
Public Sub AddDrum(ByVal thisDrum As Drum)
If Me.Drums Is Nothing OrElse Me.Drums.Count = 0 Then
thisDrum.DrumNum = 1
Else
thisDrum.DrumNum = Me.Drums.Max(Function(d) CInt(d.DrumNum)) + 1
End If
thisDrum.DateEntered = Now
Me.Drums.Add(thisDrum)
End Sub
In a WinForm, I have SampleBindingSource and DrumsBindingSource, which has SampleBindingSource as its datasource and "Drums" as its DataMember. If I call the second AddDrum overload, the Drums entityset in the instance of Sample increments by one, as does the Drums member of SampleBindingSource. However, this change does not occur in the DrumsBindingSource.
I have tried ResetBindings(false and true) and EndEdit for both SampleBindingSource and DrumsBindingSource. Nothing seems to cause the changes to occur in the DrumsBindingSource.
How can I solve this problem?
I posted an answer to a similar problem I had at a later date:
Child bindingsource bound to child entityset does not update