Follow @RoyOsherove on Twitter

Automatic Data-Relations

Greg asks about data relation support in Yukon. Meanwhile, in the present, there are several ways to avoid building those relations manually in code:

  • Return hierachical data from your SQL server procedures (with the FOR XML keywords). When you use ExecuteXMLReader() against this data, you can make your dataset read the XML from the reader. Automagically, all the relevant data relations that appear in the returned hierarchical XML will be created within the dataset. You get the added benefit of retrieving multiple tables in a single call to SQL server.

 

  • Another way is for when you can't return XML from your queries. You can use my SchemaHelper class to automacially build any data relations between tables that are present in your dataset. The class queries the database for its underlying schema (using OleDbConnection.GetOleDbSchema()) . Right now it needs an OleDbConnection, but there is also a way to retrieve the schema data from a SqlConnection , which I hope to add to the class soon.

Cool debugging tool of the day: Developer Playground

Congratulations Lior!