我使用的是LINQ to SQL datacontext,它有一个Sample实体,Sample实体有一个子实体集Drums。我已经在Sample partial class中编写了这段代码来处理添加新鼓:
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
在WinForm中,我有SampleBindingSource和DrumsBindingSource,它有SampleBindingSource作为数据源,“Drums”作为DataMember。如果我调用第二个AddDrum重载,则Sample实例中的Drums实体集将增加1,SampleBindingSource的Drums成员也会增加。但是,DrumsBindingSource中不会发生此更改。
我已经为SampleBindingSource和DrumsBindingSource尝试了ResetBindings(false和true)和EndEdit。似乎没有任何东西导致DrumsBindingSource中发生更改。
我该如何解决这个问题?