查询数据集

Query a DataSet(查询数据集)

本文介绍了查询数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 XML 文件中的数据读入强类型 DataSet.数据最终出现在多个表中;我可以对其运行查询以创建非规范化视图以显示在 DataGrid 中吗?

I'm reading data from XML files into a strong typed DataSet. The data ends up in multiple tables; can I run queries against it to create a denormalized view to display in a DataGrid?

示例输入:

<PeopleFile>
    <address>
        <street>123 Some Street</street>
        <town>Anytown</town>
        <resident>
            <first>Jane</first>
            <last>Doe</last>
        </resident>
        <resident>
            <first>John</first>
            <last>Doe</last>
        </resident>
    </address>
    <address>
        <street>456 Tree Street</street>
        <town>Westwood</town>
        <resident>
            <first>Mary</first>
            <last>Jones-Smith</last>
        </resident>
        <resident>
            <first>Mike</first>
            <last>Smith</last>
        </resident>
        <resident>
            <first>Kate</first>
            <last>Smith</last>
        </resident>
    </address>
</PeopleFile>

期望的输出:

123 Some Street Anytown     Jane    Doe  
123 Some Street Anytown     John    Doe  
456 Tree Street Westwood    Mary    Jones-Smith  
456 Tree Street Westwood    Mike    Smith  
456 Tree Street Westwood    Kate    Smith  

我应该补充一点,除了每个文件有多个表之外,我的真实数据也被拆分到多个文件中,AFAIK 需要将这些文件加载​​到单独的 DataSets 中.

I should add that in addition to multiple tables per file, my real data is also split among multiple files which AFAIK will require being loaded into separate DataSets.

推荐答案

是的,使用 Linq.有一组特殊的扩展称为 Linq-to-Datasets.

Yes, use Linq. There is a special set of extensions called Linq-to-Datasets.

您显然需要 .NET 3.5,并添加 using System.Data;

You will need .NET 3.5 obviously, and add using System.Data;

如果您的多个文件遵循相同的架构,您应该能够将它们读入 TypedDataSet 的单独实例并 Merge() 这些实例.

If your multiple files follow the same schema you should be able to read them into separate instances of the TypedDataSet and Merge() those instances.

这篇关于查询数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:查询数据集