Newbie - DataPortal_Fetch(ByVal Criteria As Object)

Newbie - DataPortal_Fetch(ByVal Criteria As Object)

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


griff posted on Tuesday, October 17, 2006

Hi

A newbie using Using 1.53

Is this the correct implementation??

To retreive the BO using different criteria (e.g by PK or DateCreated etc) I would do something like this in DataPortal_Fetch(ByVal Criteria As Object)

If TypeOf Criteria Is GetByPK then

   GetbyPK  'code/stored proc to get by PK

elseif   TypeOf Criteria Is GetByDateCreated then

   GoGetbyPK    ' 'code/stored proc to get by DateCreated

elseif  TypeOf Criteria Is GetByOtherCriteris then  

 GoGet

else

endif

Thanks

Richard

 

 

 

 

 

 

JoeFallon1 replied on Tuesday, October 17, 2006

Yes. That is exactly how I tend to code these things.
One other thought - if you ever need to use the same Criteria type for 2 different Shared Methods then you are "stuck" because you won't know how to branch.

I added a MethodName As String Parameter to my criteria Base class to allow branching in just that case.

If TypeOf Criteria Is GetByPK then

   If MethodName="1" Then

      'do method 1 stuff

  ElseIf MethodName="2" Then

      'do method 2 stuff

  End If

End If

Note: There is nothing that says criteria classes HAVE to be embedded in the BOs that use them.
I split mine out to a separate file and tried to make them as re-useable as possible. This way I define them once and use them in many places. They have to Inherit from CriteriaBase and pass the Type of the BO to create though.

Also - in 2.x you can overload the DP methods using Criteria As Type1, Criteria As Type2, Criteria As Type3 etc. Then the DP framework calls the correct overload based on type. (Same idea as you wrote but Rocky gets to write the branching code instead of you.)

Joe

 

 

 

 

griff replied on Tuesday, October 24, 2006

Thanks Joe

(I've been away a few days)

Copyright (c) Marimer LLC