This project is read-only.

Persisting a single (new) item in a list

Jul 15, 2011 at 6:31 PM

Here is my situation.

I have an object "PERSON" and I have a list of "NOTES" for that person, through an associative table "PERSON_NOTES".  How can I add a note to an existing person and save only the note, not the person? Here is my attempt right now.

Dim col As NotesCollection = CType(_data.ParentCollection.SubDomain(COMPANY.PROJECT.Business.Collections.NotesCollection), NotesCollection)
Dim frm As New NoteEditor(col.NewItem)
If frm.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
    col.AddItem(frm.NoteItem)
    _data.NotesList.Add(frm.NoteItem)
    frm.NoteItem.Persist()
    HelperObject.ShowSavedMessage(Me)
End If

**I do all the filling of the new Note in "frm"

**I am using NHDAL

Of course this doesn't work as it only saves the note, and not the link to the Person.  The idea behind this is that the user doesn't have permission to modify the person, but can add notes to the file all they want.

 

Any suggestions?  Is there something I am missing?

Steve

Jul 23, 2011 at 7:13 AM

You must save the collection not the single element. This will save all changes in the whole container. 

_data.ParentCollection.Persist();

You may only save a single element if it has been modified, not added. This allows you to efficiently save one element but it not appropriate for all situations.