BusinessListBase.Delete() is not working. Remove throws error when i use delete

BusinessListBase.Delete() is not working. Remove throws error when i use delete

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


kam_csla posted on Thursday, August 05, 2010

[Serializable()] public class AList : BusinessListBase<AList, A>

 {

public AList()

{

MarkAsChild();

}

}

[Serializable()] public class ABusinessBase<A>

{

 }

aspx.cs

 objectAInstantiatedList[index].Delete();

GrdTest.DataSource = objectAInstantiatedList;

GrdTest.DataBind();

The objectAInstantiatedList has 3 records and once i delete the item.. the objectAInstantiatedList is not updating the count to 2 and the grid still showing 3 records. Please suggest where am going wrong..

RockfordLhotka replied on Friday, August 06, 2010

To delete a child object in a list, you call Remove on the list, not delete on the child.

kam_csla replied on Friday, August 06, 2010

Thanks for reply Lhotka.. But if i use remove then it throws error saying use delete instead and thats the reason i used delete.

objectAInstantiatedList.RemoveAt(index);

GrdTest.DataSource = objectAInstantiatedList;

GrdTest.DataBind();

RockfordLhotka replied on Monday, August 09, 2010

If your child object is actually a child object, then calling Delete() should cause an exception.

So your problem is probably that your "child" objects are not being created as child objects (you aren't using the child data portal, or calling MarkAsChild()).

If you are using any reasonably modern version of CSLA (3.5 or higher) you should consider using the child data portal, because that takes care of these details for you.

kam_csla replied on Monday, August 09, 2010

Thanks for the reply. You are correct.. A is Businessbase and Alist is BusinessListBase

public class A : BusinessBase<A>

public class AList : BusinessListBase<AList, A>

I created a factory method DeleteA in A which calls DataPortal_Delete()

The objectAInstantiatedList[index].Delete() wont work like you explained. But how will the A's Portal delete know that it has to delete from objectAInstantiatedList object.

RockfordLhotka replied on Monday, August 09, 2010

Have you read Expert 2008 Business Objects chapters 1-5 and 17-18? I strongly recommend reading or rereading those chapters, as they explain pretty completely how this all fits together.

kam_csla replied on Thursday, August 12, 2010

I have read the chapters and that clears some of my questions.You are correct the child objects am talking is not actually a child object. 'A' is a businessbase and Alist is business list base. So 'A' is a parent and i cant remove a parent using remove. I can delete that using dataportaldelete but the thing is that will actually delete from the database with some criteria as parameters. But the situation here is... user will keep on adding A's to Alist manually and they are in session memory. So when i use dataportal delete i cant really delete it from Alist as its not saving to database. Please suggest...

Copyright (c) Marimer LLC