Hi,
I have the classes structure like the below:
Parent : BusinessBase
ChildList : BusinessListBase<childLits, Child>
Child : BusinessBase
In the parent, included the childList as the property. The ChildList has the remove method which will remove the child from the childlist collection. Then from the Parent's DataPortal_DeleteSelf, how we delete the child objects which are in childlist collection based on the childId?
Parent class:
Private override void DataPortal_DeleteSelf()
{
Here need to do like for each child in deletedList, How to call the child's DeleteSelf method?
}
from the UI: Parent.ChildList.Remove(child1);
parent.Save() -> This will call the Parent's DeleteSelf method. Then How to achieve the above?
No, I do not want to delete from the parent in the stored procedure. I want to delete the selected child items from the childlist not all? Thatswhy from the parent, I need to call the Child_Deleteself method by passing the childId like
foreach(child c in deletedlist)
{
c.delete_self(c.Id);
}
I need to do the above for loop in the Parent's deleteself method. But in that method deletedlist not available? How to achieve this?
KJosh:
from the UI: Parent.ChildList.Remove(child1);parent.Save() -> This will call the Parent's DeleteSelf method. Then How to achieve the above?
No, if you remove a child then parent.Save() will call the parent's DataPortal_Update, not the parent's DeleteSelf. It will only call the parent's DeleteSelf if you actually delete the parent.
Again, I suggest that you look at the ProjectTracker example. See how Project.cs calls DataPortal.UpdateChild( ... ). That will call the child's Child_Insert, Child_Update or Child_DeleteSelf as required. CSLA does all the looping and "magic" for you.
Project tracker doesn't show it but you can reduce the code slightly more. Instead of DataPortal.UpdateChild ( ... ) you can simply call FieldManager.UpdateChildren( ... ). That does the same thing except that it will do all child collections if you have more than one. The parameters are a parameter array so you can pass anything. Those parameters are passed to the Child_Insert, Child_Update or Child_DeleteSelf so it is very flexible. Very cool
Copyright (c) Marimer LLC