Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Saving nonBound EntityList back to BO.CurrentDataSet
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01311289
Message ID:
01311327
Views:
29
Patrick,

>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?

It's hard to get the full sense of what you're doing as I look at the code outside the context of your application, but are you aware that if you register a business oject as a child object, MM .NET will automatically roll back the transaction for parent/child for you? Check out the MM .NET Dev Guide topic "Working with Transactions" for details.

Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform