Dynamic List Base Removing Items Never Calls DataPortal

Dynamic List Base Removing Items Never Calls DataPortal

Old forum URL: forums.lhotka.net/forums/t/11985.aspx


thaehn posted on Thursday, May 16, 2013

When I remove an item from a Dynamic List, Shouldn't the Update be called right away?  Here is the code from the View Model:

        private void OnDeleteSessionConfirmDialogClosed(IMessageBox messageBox)

        {

            if (messageBox.WasSelected(MessageBoxButtons.Yes))

            {

                Model.SessionList.Remove(Session);

            }

        }

I tried to save after it was removed, but the object was marked as busy and I couldn't apply edits:

        private void OnDeleteSessionConfirmDialogClosed(IMessageBox messageBox)

        {

            if (messageBox.WasSelected(MessageBoxButtons.Yes))

            {

                Model.SessionList.Remove(Session);

                Session.ApplyEdit();

                Session.BeginSave((o, e) =>

                    {

                        if (e.Error != null)

                        {

                            throw e.Error;

                        }                        

                    });

            }

        }

I don't think I need to do this as the Dynamic List should save automatically...Correct?  It does dissappear off the list in the datagrid, but it never disappears from the database...any help would be appreciated!  I am using Silverlight 5 with CSLA 4.3 (I believe).

Todd

 

RockfordLhotka replied on Saturday, May 18, 2013

If I remember correctly, the dynamic root list class only triggers insert/update/delete operations due to data binding behaviors, not arbitrary method calls. In other words, to trigger its automatic behavior through code your code will need to simulate normal datagrid method/event calls.

JonnyBee replied on Sunday, May 19, 2013

No, it's not just the data binding behaviors. But you must make sure to set the correct metastate of the object.

Look at the code from DynamicListBase:

    protected override void RemoveItem(int index)
    {
      T item = this[index];
      if (item.IsDeleted == false)
      {
        // only delete/save the item if it is not new
        if (!item.IsNew)
        {
          item.Delete();
          SaveItem(index);
        }
        else
        {
          SafeRemoveItem(index);
          OnSaved(item, null);
        }
      }
    }

If the item.IsNew is true or item is already deleted then nothing needs to be done - right!

So make sure that your object has the correct metatate and if you override RemoveItem in our implementation make sure to call base.RemoveItem.

thaehn replied on Tuesday, May 21, 2013

I found the solution.  I had the Object Factory attribute on the dynamic list object, but not on the business object.  The other functions worked, but the removing did not.  I use copied the attribute form the dynamic list object to the business object and it worked perfectly:

    [Csla.Server.ObjectFactory("OagInvoice.OagInvoiceSessionDal")]

Todd

Copyright (c) Marimer LLC