I have a child BLB with BusinessCore. when I save the RootOjbect. the Child_Insert and Child_Update work well, but the Child_deleteSelf doesn't work. what's wrong?
private void Child_DeleteSelf()
{
using (var ctx = DALFactory.GetManager())
{
var dal = ctx.GetProvider<IPermissionDAL>();
using (BypassPropertyChecks)
{
dal.Delete(this.Id);
}
}
}
Hi,
If you use DataPortal.UpdateChild or DataPortal.UpdateChildren on the child BLB then all Child_Insert, Child_Update and Child_DeleteSelf must have the same signature, ie if you send in the parent of the objkect as parameter then something like this:
private void Child_Insert(object parent)
{
// TODO: insert values
}
private void Child_Update(object parent)
{
// TODO: update values
}
private void Child_DeleteSelf(object parent)
{
// TODO: delete values
}
The other important part is object state. If the deleted object has IsNew = true then there is no record to delete in the database and CSLA will NOT call Child_DeleteSelf. So it is important that you check the state of the objects in BLB.DeletedList.
So the semantic for when CSLA will call Child_DeleteSelf is:
forach (var busObj in DeletedList)
{
if (busObj.IsDeleted)
{
if (!busObj.IsNew)
{
// Call Child_DeleteSelf .....
}
}
}
I use the same signature.
private void Child_Insert(Object obj)
private void Child_Update(Object obj)
private void Child_DeleteSelf(Object obj)
but the Child_DeleteSelf does't excuted.
if i change the child class Permission:BusinessCore<Permission> to Permission:BusinessBase<Permission>. the Child_DeleteSelf will be excuted.
BO tree as below:
+Objects (BusinessListBase)
++Object (BusinessCode)
+++Permissions(BusinessListBase)
++++Permission(BusinessCore)
+++Objects(BussinessListBase)
................
the BO Object is switchable bo. it's contains a child BLB Permissions.
I checked the DeleteList in permissions. the item's IsNew is false.
Then the case is probably that the deleted item has IsDirty = false.
The IsSelfDirty method in BusinessCore should be like this:
public override bool IsSelfDirty
{
get
{
if (IsDeleted) return true;
var isSelfDirty = false;
foreach(var registeredProperty in this.FieldManager.GetRegisteredProperties())
{
// skip lazy fields (is by definition child object)
if (!registeredProperty.RelationshipType.HasFlag(RelationshipTypes.LazyLoad))
{
var fieldData = FieldManager.GetFieldData(registeredProperty);
// fielddata object implements ITrackStatus it is a child object and must be excluded
if (!fieldData is ITrackStatus)
{
if (this.FieldManager.IsFieldDirty(registeredProperty))
{
isSelfDirty = true;
break;
}
}
}
}
return isSelfDirty;
}
}
Thank You. It work.
if in the child collection( BLB) there are 2 items as below
ItemA
ItemB
I Add Item C into the collection. the ViewModelBase CanSave become true. then and I delete Item C. CanSave become false. it's OK.
If I delete Item A, the CanSave Become true. then I Add Item A(use Item.NewItem() and add into collection, all propertys is as same as the lay in the DeleteList), but the CanSave still true.
Copyright (c) Marimer LLC