views:

94

answers:

1
+1  Q: 

Query a DataSet

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?

Sample input:

<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>

Desired output:

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

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

+1  A: 

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

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

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.

Henk Holterman
The files follow several different schemas, so at a minimum Merge()ing won't work.
Dan Neely
There is also a Merge() at the Table level. But you will need to elaborate a bit on the Dataset(s), eg do the tables have Id's etc.
Henk Holterman
Yes. My app was originally written using XmlSerialization and all the distinct objects had key values whose uniqueness needed to be maintained in code. Getting away from that is a significant part of why I'm trying to change over to read into DataSets instead. The DataSet representation broke some objects into multiple tables (eg where an A contained an array of B's); in these cases the keys were manually created.
Dan Neely
A single file will contain what was originally a single array of objects of a single type + misc file header data.
Dan Neely
Can I get the DataSet's into a graphical query designer? I've never used linq before, and have always struggled to write non trivial sql by hand.
Dan Neely
Better work some details in the question (or a new one). This trail of comments is going nowhere.
Henk Holterman