Class RBI.Lead:
Public Class Lead
#Region "Constructors "
Public Sub New()
_cxt = New RDB.RDBContainer
_person = New RDB.Lead
End Sub
Public Sub New(ID As Guid)
If Not IsNothing(ID) Then
If IsNothing(_cxt) Then _cxt = New RDB.RDBContainer
If IsNothing(_person) Then
_person = _cxt.Leads.Find(ID)
End If
End If
End Sub
#End Region
...
Public ReadOnly Property Notes As IEnumerable(Of RBI.PersonNote)
Get
If Not IsNothing(_person.LeadNotes) Then
Dim _tmp As IEnumerable(Of RiseBI.LeadNote) = _person.PersonNote.Select(Function(p) New RBI.PersonNote(p, _cxt))
Return _tmp.ToList
Else
Return Nothing
End If
End Get
End Property
...
End Class
RDB.Lead:
Partial Public Class Lead
Public Property Id As System.Guid
...
Public Overridable Property LeadNotes As ICollection(Of LeadNote) = New HashSet(Of LeadNote)
End Class
向潜在客户添加新备注:
Public Shared Function AddNote(ID As Guid, Note As String) As Guid
Dim _cxt As New RDB.RDBContainer
Dim _tmp As New RDB.PersonNote
Dim _person = DB.Leads.Find(ID)
_tmp .Id = Guid.NewGuid()
_tmp .Note = Note
_lead.LeadNotes.Add(tmp)
DB.SaveChanges()
Return _tmp.ID
End Function
UI方面的事情: 添加新笔记:
Protected Sub modNotes_save_Click(sender As Object, e As EventArgs) Handles btnModalNotes.Click
LeadFunctions.AddNote(Guid.Parse(RouteData.Values("pid")), txtModalNotes.Text)
PHSuccess.Visible = True
lblMasterSuccess.Text = "Notes updated"
listNotes.Rebind()
End Sub
ListNotes数据源定义为:
Protected Sub ListNotes_NeedDataSource(sender As Object, e As RadListViewNeedDataSourceEventArgs)
Dim _person As New RiseBI.Lead(CStr(RouteData.Values("pid")))
ListNotes.DataSource = _person.Notes
End Sub
添加备注时,它会显示在数据库中。但是,即使listview是重新绑定,它也会显示旧数据,而不是新数据。