c# - 查询数据集

标签 c# xsd datatable dataset

我正在将 XML 文件中的数据读入强类型 DataSet。数据最终出现在多个表中;我可以针对它运行查询以创建非规范化 View 以显示在 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 中。

最佳答案

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

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

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

关于c# - 查询数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1869022/

相关文章:

javascript - 从数据表中删除 dataTable 类

xml - JSON 架构与 XML 架构

web-services - Soap WSDL ComplexType 被发布为错误的参数类型

c# - “密封类中的 protected 成员”警告(单例类)

c# - 如何在 C#/VS 中构建自定义断言?

java - 如何使用t24格式发送SOAP请求

java - 丰富的 :dataTable zebra cells with css

java - Primefaces 中的过滤器 DataTable 仅工作一次

c# - 在 C# 中执行时将自定义变量添加到应用程序路径的末尾

c# - 如何使用 TDD 测试没有 args 构造函数和 setter 的外观类?