How to use BO.FillMultipleDataTables for parent, child, grandchild tables?


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I am trying to fill the data for 3 BOs which will be used in a report, I am trying to use the BO.FillMultipleDataTables to get the data, but when creating the SQL for the grand child, I don't know how to reference the PK value in the SQL statement.

Here my code for Parent ->Child:

Public Shared Function ServiceCallMaintenance_AllData(ByVal PK_ServiceCalls As Integer, ByVal includeServiceCallRecord As Boolean) As SqlCommand

     '-- Establish Locals

     Dim cmd As New SqlCommand()

     '-- Determine if the Service Call record will be included

     If includeServiceCallRecord Then

          cmd.CommandText = "SELECT dbo.ServiceCalls.* FROM dbo.ServiceCalls WHERE dbo.ServiceCalls.PK_ServiceCalls = @PK_ServiceCalls;"

     End If

     '-- Add the Appliances query for the selected Service Call, ordered by the Appliance Service Date.

     cmd.CommandText &= "SELECT dbo.SC_Appliances.* FROM dbo.ServiceCalls " & _

"INNER JOIN dbo.SC_Appliances ON (dbo.ServiceCalls.PK_ServiceCalls = dbo.SC_Appliances.FK_ServiceCalls) " & _

"WHERE (dbo.SC_Appliances.FK_ServiceCalls = @PK_ServiceCalls)" & _

"ORDER BY dbo.SC_Appliances.ServicedDate;"

     '-- Create the parms

     cmd.Parameters.AddWithValue("@PK_ServiceCalls", PK_ServiceCalls).SqlDbType = SqlDbType.Int

     '-- Return the results

     Return cmd

End Function

This code works fine, but if I want to add a grandchild table SC_AppliancesItems which is related to SC_Appliances I don't know to make a reference to SC_Appliances.PK_SC_Appliances in the SQL statement to get all related records to fill the grandchild BO.

How can I accomplish that?

Please see attached relation diagram.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
A couple of things here, Edhy.  First of all, I would pull this code out of the plain text in the BO and create a stored procedure on the SQL side so that you can tell what is going on.  In this scenario, I just assumed that a service call PK would be passed over, but you can adjust the query accordingly.   Here is a stored procedure that will return 3 result sets which includes the parent, child, and grand child records.

CREATE PROCEDURE dbo.MyReportQuery
@serviceCalls
INT
AS
BEGIN

-- RESULT SET #1
-- Retrieve the service service call
SELECT
*
FROM ServiceCalls
WHERE PK_ServiceCalls = @serviceCalls;

-- RESULT SET #2
-- Rerieve all of the appliances for the specified service call
SELECT
SC_Appliances.*
FROM SC_Appliances
    LEFT JOIN ServiceCalls ON PK_ServiceCalls = FK_ServiceCalls
WHERE ServiceCalls.PK_ServiceCalls = @serviceCalls;

-- RESULT SET #3
-- Retrieve all of the appliance items for the service call
SELECT
SC_ApplicancesItems.*
FROM SC_ApplicancesItems
   
LEFT JOIN SC_Appliances ON PK_SC_Appliances = FC_SC_Appliances
   
LEFT JOIN ServiceCalls ON ServiceCalls.PK_ServiceCalls = SC_Appliances.FK_ServiceCalls
WHERE ServiceCalls.PK_ServiceCalls = @serviceCalls;

END

Next, you will use this sproc to populate your BOs.  Genreally, I will create a base BBS which then exposes the child BO via a BBS and then that will have the grandchild in it exposed, etc.  You just go as deep as you need to go.

Dim ServiceCalls As New ServiceCallsBBS()
Dim cmd As New SqlCommand("dbo.MyReportQuery")

cmd.CommandType = StoredProcedure
cmd.Parameters.Add("@serviceCallPk", SqlDbType.Int).Value = ServiceCallPK

BusinessLayer.FillMultipleDataTables(cmd, _
                                                 ServiceCalls.BusinessObject, _
                                                 ServiceCalls.BusinessObject.Appliances.BusinessObject, _
                                                 ServiceCalls.BusinessObject.Appliances.BusinessObject.ApplianceItems.BusinessObject)



Dustin Taylor
Dustin Taylor
StrataFrame Team Member (938 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
One other note: when using the above you are going to get ALL child and grandchild records for ALL of their respective parents. This means that you will likely need to filter them down when accessing to only those records that apply to the current parent.

So, where trent has "ServiceCalls.BusinessObject.Appliances.BusinessObject" on his FillMulitpleDataTables, he has actually created an internal AppliancesBBS within his ServiceCallsBO. On the public property used to access that AppliancesBBS, you can set the filter on the Get, and it will handle the rest for you:

''' <summary>
''' Returns the patient records
''' </summary>
Public ReadOnly Property Appliances() As AppliancesBBS
Get
'-- Set the filter
If Me.Count > 0 Then
'-- Apply the filter
_Appliances.BusinessObject.Filter = "FK_serviceCalls = " & Me.PK_ServiceCalls
End If
'-- Return the filtered appliances BBS
Return _Patients
End Get
End Property


Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Excellent guys, I have been trying to stay away of store procedures, but guess it is time to jump in and beat the fear Hehe

You both gave me enough to material to start working on this. Thanks!

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi guys,

Just to show you how your help pay off Tongue.  Please take a look at the attached image to see my 1st RSS report.  Thanks again for your continued support!

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Cool...looks good! Smile
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Bacana! Cool
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search