EditableRootListBase Woes

EditableRootListBase Woes

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


JohnB posted on Friday, February 01, 2008

I have some issues I'm trying to work through with the ERLB. I'm close but I am starting to wonder if I am using the right Csla base class for what my use case calls for.

I have a grid/listbox (ERLB) filled with BB objects. I don't want the ERLB to save immediately as it is designed for nor do I want to use a BLB which supports the batch updates. I want the user to select an item from the grid/list, edit, and me force the save.

The number of objects that I am loading are relatively small (10-150), so I figured that I would get everything in one trip since I don't have to worry about concurrency issues and I don't have to repeatedly hit the db while the user clicks around.

Is the ERLB the best 'tool' for this? Am I way off?

Thanks,
John

RockfordLhotka replied on Friday, February 01, 2008

You need to do this in your subclass of ERLB:

  1. Override SaveItem() so it is a no-op
  2. Add your own ManualSaveItem() method that calls base.SaveItem()

In the UI:

  1. Call your ManualSaveItem() when you want to save an item

 

JohnB replied on Friday, February 01, 2008

RockfordLhotka:

In the UI:
  1. Call your ManualSaveItem() when you want to save an item


Ok, so it should look like the following?

    Public Sub SaveMyItem(ByVal accountToSave As Account)
        MyBase.SaveItem(accountToSave)
    End Sub

    Public Overrides Sub SaveItem(ByVal index As Integer)
        '-- Do nothing
    End Sub

RockfordLhotka replied on Friday, February 01, 2008

I think that should work, yes. Though I can’t say I’ve tested it, so there could be unforeseen complications (especially around removing items perhaps?).

 

Rocky

 

 

From: JohnB [mailto:cslanet@lhotka.net]
Sent: Friday, February 01, 2008 1:06 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] EditableRootListBase Woes

 

RockfordLhotka:


In the UI:

  1. Call your ManualSaveItem() when you want to save an item



Ok, so it should look like the following?

    Public Sub SaveMyItem(ByVal accountToSave As Account)
        MyBase.SaveItem(accountToSave)
    End Sub

    Public Overrides Sub SaveItem(ByVal index As Integer)
        '-- Do nothing
    End Sub


JohnB replied on Thursday, February 07, 2008

Rocky,

That almost worked. I had to do a little more work to get it just right.

First, for SaveMyItem, I was unable to just call MyBase.SaveItem(accountToSave). ERLB uses the index position to save the object. So I had to do the following:

Public Sub SaveMyItem(ByVal accountToSave As Account)
        MyBase.SaveItem(Me.IndexOf(accountToSave))
End Sub


No big deal. The delete was rather interesting like you mentioned since upon calling ERLB.Remove, the object is removed from the collection. That means the SaveMyItem would fail since Me.IndexOf(accountToSave) is -1. The solution was to override RemoveItem:

Protected Overrides Sub RemoveItem(ByVal index As Integer)
        Account.DeleteAccount(Me.Item(index).UserID)
        MyBase.RemoveItem(index)
End Sub


So I call my factory method on the object to delete it and then remove it from the collection. This works fine. So at this point it is doing everything I wanted it to do. Not sure if this is the best implementation but it gives me the functionality that I need.

Thanks,
John

Copyright (c) Marimer LLC