2

I recently posted this on http://forums.lhotka.net/ , but I'm not getting a response. Hopefully I have better luck here. Here is my problem.

I'm using CSLA .NET 4.5, and 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 and one of them is parameterless, the parameterless one won't be called. Even if you specify the DataPortal.UpdateChild with no additional parameters beyond the Child Object.

Example in pseudo code:

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);
}

Now I know CSLA uses Reflection to find the correct data access method to call, however I'm not sure why a parameterless method would not be distinguishable from a parameterized one based on the arguments passed to DataPortal.UpdateChild? Could this be a CSLA bug or am I missing something?

Brett Janer
  • 517
  • 1
  • 4
  • 20

1 Answers1

2

Hmm, I suspect this could be a bug in Csla. Try changing the Child_Update() to Child_Update(SomeLegacyParent) so you no longer have a parameterless Child_Update. You may have to change the legacy parents call to UpdateChild to pass 'this' as well.

Edit: Per the thread linked to in this answers comments, this issue has been fixed in Csla.

Andy
  • 8,432
  • 6
  • 38
  • 76
  • In CSLA, inheritance is not used to build the object graph's parent-child relationships. It is done through properties. I edited the parent classes to reflect the child property. – Brett Janer Aug 16 '13 at 03:08
  • @BrettJaner I realize that; however, I'm trying to point out that your Child_Update expects a base class of ParentBusinessBase, but none of your parents inherit from it, so Csla wouldn't match the signature of the child update b/c its looking at the type hierarchy of your parent classes. – Andy Aug 16 '13 at 13:45
  • Oh yes sorry I misread your post, but you are correct. Copy and paste error on my part. ParentBusinessBase should be SomeNewParent. I've edited the question to reflect this. – Brett Janer Aug 16 '13 at 14:31
  • @BrettJaner Updated my answer based on your revised code. If my suggestion works, consider submitting a small sample project to the Csla forums to see if its a big. Rocky is recovering from surgery so it might be a while for a response, or maybe one of the contributors can handle it. – Andy Aug 17 '13 at 14:47
  • 1
    I'm assuming I'm just going to have to wait it out on the CSLA forums. Thanks Andy for your answer. It is my current workaround, and a valid solution. My post on the CSLA forums can be found here: http://forums.lhotka.net/forums/p/12114/56136.aspx#56136 – Brett Janer Aug 19 '13 at 22:30