How do you pass several parameters to DataPortal_Fetch()?

How do you pass several parameters to DataPortal_Fetch()?

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


superkuton posted on Friday, July 03, 2009

Hi!

How do you pass several parameters to DataPortal_Fetch()?

Is this valid?

Private Overloads Sub DataPortal_Fetch(ByVal startdate As SingleCriteria(Of ScheduleList, Date), ByVal enddate As SingleCriteria(Of ScheduleList, Date), ByVal qualification As SingleCriteria(Of ScheduleList, String))

'codes to get data

End Sub


And how do you call the procedure in the Factory Methods?


Thanks.

Vinodonly replied on Saturday, July 04, 2009

in c# book page 81, 203 this is given..

In short,

SingleCriteria can be used when you have only one parameter to pass

For multiples values (like in your case), you will have to create a class which inherits from criteriabase or create a nested class in your BO..

Remember criteria class is just a datacontainer to carry different criteria/key values to dataportal, so you can subclass and put whatever values you want and retreive in Dataportal

Vinodonly replied on Saturday, July 04, 2009

i'm not using vb, so i generated following code through a generator. This is a example of embeded criteria class in your BO, where you have two parameters

IMP : Tags not being shown here but you have to mark your criteria class as Serializable

_
Protected Class CriteriaTS

Private _empMainID As Int32
Public ReadOnly Property EmpMainID() As Int32
Get
Return _empMainID
End Get
End Property


Private _lastChanged As Byte()
Public ReadOnly Property LastChanged() As Byte()
Get
Return _lastChanged
End Get
End Property

Public Sub New(ByVal empMainID As Int32, ByVal lastChanged As Byte())
_empMainID = empMainID
_lastChanged = lastChanged
End Sub

Public Overrides Function Equals(obj As Object) As Boolean
If TypeOf obj Is CriteriaTS
Dim c As CriteriaTS = DirectCast(obj, CriteriaTS)
If Not _empMainID.Equals(c._empMainID) Then Return False
If Not _lastChanged.Equals(c._lastChanged) Then Return False
Return True
End If
Return False
End Function
Public Overrides Function GetHashCode() As Integer
Return String.Concat("CriteriaTS", _empMainID.ToString(), _lastChanged.ToString()).GetHashCode()
End Function
End Class


Then in your dataportal, you will define it like this

Protected Overloads Sub DataPortal_Delete(ByVal crit As CriteriaTS)

Using ctx = ConnectionManager(Of SqlConnection).GetManager(Database.OrdersConnection, False)
Using cmd As New SqlCommand("EmpMainDel", ctx.Connection)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@EmpMainID", crit.EmpMainID)
cmd.Parameters.AddWithValue("@LastChanged", crit.LastChanged)
Dim args As New DataPortalHookArgs(cmd, crit)
OnDeletePre(args)
cmd.ExecuteNonQuery()
OnDeletePost(args)
End Using
End Using
End Sub

superkuton replied on Saturday, July 04, 2009

Yap, I finally got it.

Thank you vinodonly.


Copyright (c) Marimer LLC