Interacting with DataPortal_XYZ methods in my base class

Interacting with DataPortal_XYZ methods in my base class

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


bgilbert posted on Friday, November 02, 2007

I need to be able to wedge some code in after certain DataPortal methods. In my base class, I've tried overriding DataPortal_Fetch, but it never gets hit. I've also tried using DataPortal_OnDataPortalInvokeComplete, but I can't see how to determine which method fired it. I saw some discussion on this last year and Rocky mentioned that he would have a fix for this, but I haven't seen anything that would help me. I'm using 3.02.

Any ideas?

DavidDilworth replied on Friday, November 02, 2007

Double check the signature for your DataPortal_Fetch() override method.  The method in your base class should look something like this:

protected override void DataPortal_Fetch(object criteria)
{
   // Your code goes here
}

bgilbert replied on Friday, November 02, 2007

David,

That is the signature I have, however, in my business class, I have to use an Overload, like this:

Private Overloads Sub DataPortal_Fetch(ByVal criteria As MyCriteriaClass)

MyCriteriaClass cannot be an override of Object, therefore I can't use:

Private Overrides Sub DataPortal_Fetch(ByVal criteria As FilterCriteria)


Barry

DavidDilworth replied on Friday, November 02, 2007

If you've got a DataPortal_Fetch() with a strongly typed criteria object (as you suggest) in your BO class, then the override method in the base class will NEVER be hit.  The DataPortal automatically detects the method signature with the strongly-typed Criteria object and calls that directly.

So if you really want to write some code in an abstract base class that will work for any BO class, then you have to work with the abstraction of a loosely-typed Criteria object.  Like the one I posted above.  That way the override will always get hit for any Criteria object from any Business Object.

That also means that you can't use a method in your BO class with a strongly-typed Criteria object.

However, inside your BO class you can then override the DataPortal_Fetch() from your abstract base class and cast the loosely-typed Criteria object to the strongly-typed Criteria object that you really want to work with.

Does that help?

bgilbert replied on Friday, November 02, 2007

Yes, it makes sense, however in many of my business classes, I have overloads of each DataPortal method, which receive different criteria objects. I would have several nested criteria classes that handle different combinations of criteria. I do this because different DataPortal methods need to call different stored procedures.

As I write this, I realize that I might be able to use one criteria class and one DataPortal method and simply pass the spoc name though the criteria class.

I'll give it a try.

Thanks.

JoeFallon1 replied on Friday, November 02, 2007

Barry,

This discussion may help a bit.

I have been passing in MethodName for a long time now.

http://forums.lhotka.net/forums/post/17535.aspx

Joe

Copyright (c) Marimer LLC