BusinessRules.CheckRules() not called on DataPortal.ChildXYZ(with param) ByDesign?

BusinessRules.CheckRules() not called on DataPortal.ChildXYZ(with param) ByDesign?

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


swegele posted on Wednesday, October 22, 2014

I noticed my rules not getting run automatically when I used the DataPortal.ChildXYZ(obj param).  But when I call it with no params ex. DataPortal.ChildXYZ() then CheckRules does get run.

Is that by design?  Am I supposed to do something in my void Child_Create(object param) methods?

MarkAsChild is getting called...so I would have thought CheckRules would too?

 

Thanks

Sean

swegele replied on Wednesday, October 22, 2014

Perhaps I am supposed to call base.ChildXYZ first thing or last thing in my version of void Child_Create?

swegele replied on Wednesday, October 22, 2014

OK I noticed this works to call the CheckRules

        private void Child_Create(object parent)
        {
            ParentId = parent.Id;
            base.Child_Create();
        }

I didn't know I was supposed to call base.Child_Create() or base.Child_Fetch() to get that functionality.  I figured it was the dataportal actually doing the CheckRules call.

swegele replied on Wednesday, October 22, 2014

So why is CheckRules not called on ChildDataPortal_XYZ methods automatically just like DataPortal_XYZ methods?

 

JonnyBee replied on Thursday, October 23, 2014

It is all handled in the same way:

protected virtual void Child_Create()
{
  BusinessRules.CheckRules();
}
protected virtual void DataPortal_Create()
{
  BusinessRules.CheckRules();
}

and the DataPortal does NEVER call BusinessRules.CheckRules.

So - when you create other overloads on these methods it is your reponsibility to either call the base.CYZ_Create or call BusinessRules.CheckRules(). CSLA Framework / DataPortal does not enforce BusinessRules.CheckRules when you create other overloads.

Copyright (c) Marimer LLC