[英]BizTalk WCF SQL Adapter: How to receive records from a database with one-to-many relationships
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. 我已经看过许多教程,讨论如何在BizTalk接收端口中使用WCF SQL适配器从SQL Server数据库中提取数据。 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. 例如,假设我有一个包含三个表的数据库:Team,Player和Sponsor。 The Team table is in a one-to-many table with the Player and Sponsor tables.
Team表位于包含Player和Sponsor表的一对多表中。 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. 我希望我的BizTalk应用程序可以轮询新的团队记录以及任何相关数据。 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.
生成的XML的XSD当然允许多个播放器和赞助商记录。
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. 我可以在技术上使用FOR XML PATH从存储过程中组装整个XML结构并将其返回给BizTalk应用程序,但是这种方法会导致不必要的复杂存储过程。 (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? 这让我想到了一个实际的问题:从数据库中检索一对多关系中的记录以构建一个我可以在我的BizTalk应用程序中使用的完全实现的XML消息的最佳实践是什么?
Is there a way do this this just using a stored procedure and the WCF SQL adapter? 有没有办法只使用存储过程和WCF SQL适配器? 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.
我能够提出的唯一解决方案是为每个表使用单独的存储过程,然后使用Map或Orchestration将各个部分组合到我的规范模式中。 Maybe this is indeed the best approach, but I would very much like to know if there is something very simple I am missing.
也许这确实是最好的方法,但我非常想知道我是否有一些非常简单的东西。
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. 然后通过Consume Adapter Service生成模式。 You will get a schema with three record sets which you can then map to a nicer schema.
您将获得具有三个记录集的模式,然后您可以将其映射到更好的模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.