2

我最近在http://forums.lhotka.net/上发布了这个,但我没有得到回复。希望我在这里有更好的运气。这是我的问题。

我正在使用 CSLA .NET 4.5,我最近向 BusinessBase 添加了一个额外的 Child_Update 方法,以支持其父 BusinessListBase 批量保存。然而,这似乎在我们的系统中引入了一个错误。看起来如果您有两个 Child_Update 方法,其中一个是无参数的,则不会调用无参数的方法。即使您指定的 DataPortal.UpdateChild 没有超出子对象的其他参数。

伪代码示例:

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

现在我知道 CSLA 使用反射来找到要调用的正确数据访问方法,但是我不确定为什么基于传递给 DataPortal.UpdateChild 的参数无法区分无参数方法与参数化方法?这可能是 CSLA 错误还是我遗漏了什么?

4

1 回答 1

2

嗯,我怀疑这可能是 Csla 中的一个错误。尝试将 Child_Update() 更改为 Child_Update(SomeLegacyParent),这样您就不再拥有无参数的 Child_Update。您可能还必须更改对 UpdateChild 的传统父母调用以传递“this”。

编辑:根据此答案评论中链接到的线程,此问题已在 Csla 中修复。

于 2013-08-15T22:45:34.597 回答