RemoveAll method required on child collection

RemoveAll method required on child collection

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


j055 posted on Tuesday, May 19, 2009

Hi

I'd like to provide a method on a child collection to remove all the collection objects and then delete all of the corresponding rows in the database with one statement. Do I have to implement this independently of the framework or can/should I do this in the Child_Update method of the collection for example?

The book seems to mainly talk about handling deletes in the collection's child object for example but it's more efficient for me to do the database delete in one hit in this case. I'm wondering if there's a consistent approach to use for such a requirement?

Many thanks
Andrew

RockfordLhotka replied on Tuesday, May 19, 2009

You have an editable root collection. A root object that inherits from BLB.

In this case you can use the immediate delete feature of the data portal, or a command object, as you choose. Either way, you are sending a message to the server to do the delete. I haven't tried this, but I think it should work (or be close anyway):

public class MyList : BusinessListBase<MyList, MyChild>
{
  public void RemoveAll()
  {
    DataPortal.Delete<Mylist>();
    this.Clear();
    DeletedList.Clear();
    MarkNew();
  }

  private void DataPortal_Delete()
  {
    // delete all items from database
  }
}

 

j055 replied on Wednesday, May 20, 2009

Hi

OK thanks, but is there a way to do something similar in a child collection? Actually, in my case it's a grandchild collection.

I tried this:

internal void RemoveAll(byte orGroup)
{
DataPortal.UpdateChild(new SingleCriteria(orGroup));
DeletedList.Clear();
Clear();
}

private void Child_DeleteSelf()
{
Debug.WriteLine("Child_DeleteSelf");
}

private void Child_Update()
{
Debug.WriteLine("Child_Update");
}

But I get System.NotImplementedException: Child_Update not implemented.

Is using the command object the way to go in this case?

Thanks again
Andrew

mbblum replied on Wednesday, May 20, 2009

In this code sample UpdateChild is passing a SingleCriteria param, but the Child_Update has no param. The method signatures do not match, which is probably the source of the Not Implemented Exception. Try adding to Child_Update the SingleCriteria param.

j055 replied on Wednesday, May 20, 2009

Hi there

Thanks for pointing that out. I have tried the SingleCriteria param among other things but I still get the System.NotImplementedException: Child_Update not implemented error.

Any ideas?
Thanks
Andrew

Fintanv replied on Thursday, May 21, 2009

If you could post the parent and the child code as it currently stands, it would help us to understand what is going on.

j055 replied on Thursday, May 21, 2009

Hi

I've been looking into my requirements in a bit more detail. I think my 'RemoveAll' method is floored because I can just delete it's parent. This is my first real CSLA project do I'm still getting to grips with some of the concepts.

One thing you might be able to clear up for me. Is it acceptable to use DataPortal.Delete in a child object? E.g.


internal static FilterParameterGroup GetFilterParameterGroup(object data)
{
return DataPortal.FetchChild(data);
}

internal static void DeleteFilterParameterGroup()
{
DataPortal.Delete ();
}

Thanks
Andrew


Copyright (c) Marimer LLC