Child_Fetch not working as expected

Child_Fetch not working as expected

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


BrettJaner posted on Wednesday, August 14, 2013

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?

ajj3085 replied on Monday, August 19, 2013

Jonny, could you help determine if this is a bug or by design? If it's by design do you know the rationale?

JonnyBee replied on Tuesday, August 20, 2013

I will look into it.

JonnyBee replied on Tuesday, August 20, 2013

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. 

 

BrettJaner replied on Tuesday, August 20, 2013

@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.

JonnyBee replied on Wednesday, August 21, 2013

Merged into github repository now.

https://github.com/MarimerLLC/csla/issues/196 

Copyright (c) Marimer LLC