Using Csla 4.5
I recently added an additional Child_Update method to a BusinessBase to support its Parent BusinessListBase in bulk saving. However, this seemed to of introduced a bug in our system. It looks like if you have two Child_Update methods, the parameterless one won't be called. Even if you specify the DataPortal.UpdateChild with no additional parameters beyond the Child Object.
public class SomeChild : BusinessBase<SomeChild>
{
//No longer called
private void Child_Update() {}
//Newly added
private void Child_Update(SomeNewParent parent) {}
}
public class SomeLegacyParent : BusinessBase<SomeLegacyParent>
{
private static readonly PropertyInfo<SomeChild> SomeChildProperty =
RegisterProperty<SomeChild>(x => x.SomeChild, RelationshipTypes.Child);
public SomeChild SomeChild
{
get { return GetProperty(SomeChildProperty); }
set { SetProperty(SomeChildProperty, value); }
}
//Use to call Child_Update(), but now
//calls Child_Update(SomeNewParent parent)
DataPortal.UpdateChild(ReadProperty(SomeChildProperty));
}
public class SomeNewParent : BusinessBase<SomeNewParent>
{
private static readonly PropertyInfo<SomeChild> SomeChildProperty =
RegisterProperty<SomeChild>(x => x.SomeChild, RelationshipTypes.Child);
public SomeChild SomeChild
{
get { return GetProperty(SomeChildProperty); }
set { SetProperty(SomeChildProperty, value); }
}
//Calls Child_Update(SomeNewParent parent) --- as expected
DataPortal.UpdateChild(ReadProperty(SomeChildProperty), this);
}
I've attached a small code sample which demonstrates the above. Is this a bug?
I will look into it.
It seems to be by design - as the internal code will pass null as parameter and so the MethodCaller will look a method that has on parameter (by default) and only call the non-parameter method when there is no method with that name that accepts on parameter.
This behavior _may_ be changed/updated and the only place where this is done right now is when calling Child_Update on a list/collection - not on a direct child object.
I do agree that this behavior should be the same whether you call into a single child object or a list of child objects. So in my opinion this is a bug.
@Rocky - please comment if you disagree with me.
@JonnyBee - Thanks for looking into this for me.
I just would like to add something. Inside ChildDataPortal.Update the following call is made:
lb.CallMethod("Child_Update", parameters);
This LateBoundObject function internally makes the call to MethodCaller.CallMethod(obj, method, hasParameters, parameters) with hasParameters = true, so regardless if it is a direct child or not, I get similar results.
Merged into github repository now.
Copyright (c) Marimer LLC