Introduction
In this tutorial we will show you how to connect to Microsoft SQL Server and use stored procedures to create an association between two External Content Types using BCS Meta Man.
We are going to follow on from the ‘BCS Meta Man – Using Stored Procedures – Adding a Specific Finder and IdEnumerator’
Prerequisites
- SharePoint Foundation 2010 or SharePoint Server 2010
- Visual Studio Professional or higher
- BCS Meta Man
- AdventureWorks SQL Database
- A SQL Stored Procedure for the Finder Method for the Orders Table such as
USE [AdventureWorks] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Lightning Tools Ltd -- Create date: 07/16/2010 -- Description: Sample Stored Procedure to return Order information -- ============================================= CREATE PROCEDURE [dbo].[uspGetOrders] -- Add the parameters for the stored procedure here AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT CustomerID, SalesOrderID, TotalDue FROM SalesLT.SalesOrderHeader END GO
- A SQL Stored Procedure for the association such as
USE [AdventureWorks] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Lightning Tools Ltd -- Create date: 07/16/2010 -- Description: Sample association Stored Procedure to return Orders by Customer ID -- ============================================= CREATE PROCEDURE [dbo].[uspGetOrdersByCustomerID] -- Add the parameters for the stored procedure here @CustomerID int = 0 AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT SalesLT.Product.Name,
SalesLT.SalesOrderDetail.OrderQty,
SalesLT.SalesOrderHeader.TotalDue,
SalesLT.SalesOrderHeader.CustomerID, SalesLT.SalesOrderDetail.SalesOrderID,
SalesLT.Product.Color FROM SalesLT.SalesOrderDetail INNER JOIN SalesLT.SalesOrderHeader ON SalesLT.SalesOrderDetail.SalesOrderID = SalesLT.SalesOrderHeader.SalesOrderID
INNER JOIN SalesLT.Product ON SalesLT.SalesOrderDetail.ProductID = SalesLT.Product.ProductID WHERE (SalesLT.SalesOrderHeader.CustomerID = @CustomerID) END GO
Walkthrough
Complete the ‘BCS Meta Man – Using Stored Procedures – Adding a Specific Finder and IdEnumerator’ Tutorial
- You should have the following External Content Type on your Diagram
- From the ‘BCS Meta Man Data Source Explorer’ drag and drop your ‘Orders’ Stored Procedure Finder Method onto the diagram
- Name the External Content Type ‘Order’, Click ‘OK’
- Select ‘Finder’ as the Method Type, Click ‘OK’
- You should now have 2 External Content Types on the diagram
- Switch to the ‘Toolbox’ pane in Visual Studio (Ctrl-Alt-X)
- Select the ‘Association’ toolbox item from the list
- With the Association selected, Click and Drag from ‘Customer’ to ‘Orders’
- When you release the ‘Association Configuration’ dialog will show
- Switch back to the ‘BCS Meta Man Data Source Explorer’ tool window pane
- Drag the Association Stored Procedure onto the Arrow in the ‘Association Configuration’ dialog, it will turn green when OK to release.
- The dialog will update with the selected Stored Procedure
- Select ‘CustomerID’ in both the Parameter and Identifier drop-down list boxes, Click ‘Save’
- The diagram will update to show an arrow indicating we have an association between the two External Content Types
- Press F5 to deploy, this will load up your SharePoint Page once deployed
- Add a new Business Data List Web Part to your SharePoint page
- Click on the ‘Open the tool pane’ link
- Click on the icon to show the available External Content Types
- Select our ‘BCSMetaManStoredProcedure.Customer’ External Content Type, click OK
- Click ‘OK’ on the tool pane
- Click the ‘Add’
- Your External System data is now displayed in the SharePoint Web Part
- Next, Add a new ‘Business Data Related List’ Web Part to the page
- Configure the Web Part to use the ‘Orders’ External Content Type
- The Web Part will display a message saying the following
- To do this we can set up the connection using the small arrow from the top right of our Web Part
- Once this is done we can click on the arrows next to an item in our ‘Customer’ web part and their orders will display on our ‘Orders’ web part
<phill/>