BizTalk WCF SQL Adapter: How to receive records from a database with one-to-many relationships

两盒软妹~` 提交于 2019-12-11 06:11:59

问题


I have seen many tutorials going over how to use the WCF SQL adapter in a BizTalk receive port to pull in data from a SQL Server database. However, I have been unable to find any resources on how best to handle this same kind of operation when the data you are working with has a one-to-many relationship.

For example, say I have a database with three tables: Team, Player and Sponsor. The Team table is in a one-to-many table with the Player and Sponsor tables. Basically, a Team can have many Players, but a Player can only belong to one Team. Likewise, a Team can have multiple Sponsors, but a Sponsor will only support one Team.

I want my BizTalk application to poll for new Team records along with any related data. When a new Team is added, I want to use a stored procedure to pull in that Team as well as all Players and Sponsors for that Team. The XSD for the resulting XML will of course allow for multiple Player and Sponsor records.

I could technically use FOR XML PATH to assemble the entire XML structure from within the stored procedure and return that to the BizTalk application, but that approach would result in an unnecessarily complicated stored procedure. (I'm not really working with such a small database structure. That was just an example for the sake of simplicity.)

This brings me to my actual question: What are some best practices for retrieving records in a one-to-many relationship from a database to construct a fully-realized XML message that I can use in my BizTalk application?

Is there a way do this this just using a stored procedure and the WCF SQL adapter? The only solution I have been able to come up with is to use a separate stored procedure for each table, then use a Map or Orchestration to assemble the various pieces into my canonical schema. Maybe this is indeed the best approach, but I would very much like to know if there is something very simple I am missing.


回答1:


Your stored procedure should look something like this.

SELECT [TeamName] 
FROM [Team]
WHERE [TeamID] = @NewTeamID

SELECT [PlayerName]
FROM [Player]
WHERE [TeamID] = @NewTeamID 

SELECT [SponsorName] 
FROM [Sponsor]
WHERE [TeamID] = @NewTeamID 

Then generate the schema from that via Consume Adapter Service. You will get a schema with three record sets which you can then map to a nicer schema.



来源:https://stackoverflow.com/questions/37668583/biztalk-wcf-sql-adapter-how-to-receive-records-from-a-database-with-one-to-many

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!