Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Saving nonBound EntityList back to BO.CurrentDataSet
Message
From
16/04/2008 16:35:36
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Saving nonBound EntityList back to BO.CurrentDataSet
Miscellaneous
Thread ID:
01311289
Message ID:
01311289
Views:
88
Hi,

I'm trying to use an EntityList mmBindingList, as a child of a parent BO.

The parent can have many notes records, like an activity list.

The interface shows old notes as Read Only (formated in a label) and allows appending a new note from a textBox. The formatting requires (so far as I can see) non-binding controls.

I want to have the child save participate in the parent save transaction. But it's tricky.

1)----------------------------------------

To add, I'm doing:
// the real code saves user, date, status codes, etc. to Note object
public static void AppendNote(mmBindingList<NoteEntity> eNotes,
        string s)
{
  if (!mmUtils.Empty(s))
  {
    NoteEntity note = eNotes.AddNew();
    note.someString = s;
    eNotes.EndNew(eNotes.Count);
  }
}    
But when I go to save, the BO DataSet isn't changed.

This (below) works, but is there a better way to do it?
public static void AppendNote(mmBindingList<NoteEntity> eNotes, 
        NoteBusinessObject oNote,
        string s)
{
  if (!mmUtils.Empty(s))
  {
    NoteEntity note = eNotes.AddNew();
    note.SetDataRow(oNote.NewRow());   // NEW code to set row *******
    note.someString = s;
    eNotes.EndNew(eList.Count)
  }
}    
2)----------------------------------------

The save code, if NOT mmSaveDataResult.RulesPassed, has to roll back the note.
// App_code Note utilities
public class NoteUI
{
// NEW change to return count of Note List
public static int AppendNote(mmBindingList<NoteEntity> eNotes, 
        NoteBusinessObject oNote,
        string s)
{
  int count = 0;

  if (!mmUtils.Empty(s))
  {
    NoteEntity note = eNotes.AddNew();
    note.SetDataRow(oNote.NewRow());   // NEW code *******
    note.someString = s;
    eNotes.EndNew(eList.Count);
    
    count = eList.Count;
  }
  return count;
}    
}

// myPage.aspx.cs
// ...
private void DoBasicSave() 
{
  // always save new comments
  int noteCount = NoteUI.AppendNote(eNotes, oNote, this.txtComments.Text);

  // Save the DataSet (automatically binds back)
  mmSaveDataResult saveResult = this.Save(this.oParent, this.dsParent);

  if (saveResult == mmSaveDataResult.RulesPassed)
  {
     // go back to list
     Response.Redirect("default.aspx");
  }
  else
  {
     // some kind of error, roll back comment to NOT save repeatedly
     if (noteCount > 0)
     {
        eNotes.RemoveAt(noteCount);
     }
  }
}
I would imagine this is a somewhat common problem. Anyone have a better way to do it?
(I'm not going to use a GridView...)
Thanks!
Next
Reply
Map
View

Click here to load this message in the networking platform