对数据集进行非规范化
我有一个数据集,其中包含一些与数据关系(经典订单标题/详细信息对)链接在一起的数据表。 有没有一种简单的方法可以将整个数据非规范化为包含相关表的所有列的单个 DataTable ?
表名和列在编译时未知,并且可能有两个以上的表/关系。
I have a DataSet with some DataTables that are linked together with DataRelations (classic order Header/Detail pair). Is there an easy way to denormalize the whole lot into a single DataTable with all the columns of the related tables?
The table names and columns are not known at compile time, and there may be more than two tables/relations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己也有同样的问题,但由于这个问题没有答案,我不得不自己编写非规范化器。 事实证明,这并不是那么困难 - 所以这是您(或遇到此问题的其他人)可能能够使用/扩展的第一个切口:
Had the same problem my self, but since this question didn't have an answer I had to write the denormalizer my self. Turned out it wasn't all that difficult - so this is a first cut that you (or some one else who run into this problem) might be able to use/extend:
我认为数据集本身并不支持这一点,但在代码中很容易做到。
首先,您应该创建一个空数据表,然后从要合并的两个表中添加所需的所有列。
然后,您逐步浏览主表中的数据,并逐步浏览相关表中的所有相关行。 对于相关表中的每一行,您在新表中创建一个新行,并将两个数据行中的数据插入到新表中。
我现在无法访问这里的视觉工作室,但你明白了。
I don't think data sets support this natively, but it is easy enough to do in code.
First you should create an empty data table and then add all the columns you need from both the tables you want to combine.
Then you step through the data in your main table and step through all related rows from the related table. For each row in the related table you create a new row in your new table and inserts the data from both data rows into the new one.
I don't have access to visual studio here now, but you get the idea.