Home > Articles > Web Services > XML

Creating Typed DataSets with XML Schemas

  • Print
  • + Share This
The typed DataSet lets you write code that is strongly typed, more expressive, and conveys meaning in the language of the solution domain. Paul Kimmel shows you how to visually design an XML schema and use that schema to generate strongly typed DataSets without writing a single line of code.
From the author of

DataSets, DataTables, and DataRows are the basic building blocks of ADO.NET, and they are implemented as classes. As such, you can inherit from and extend a plain vanilla DataSet (and company) and create a typed DataSet. The typed DataSet permits you to write code that is strongly typed, more expressive, and conveys meaning to the programmer in the language of the solution domain. Typed, expressive, solution domain-centric code are more than ideals; they represent hallmarks of good software designs.

Understanding Database Decomposition

There are several ways to decompose a problem. One common way, called database decomposition, is to decompose a problem in the form of the entities that represent data that will be stored in a database.

Although some experts don't consider database decomposition to be the strongest approach to software problem-solving, it is a valid approach that has been demonstrated to work. One difficulty with database decomposition is the propensity for the solution—the code—to be implemented in the vernacular of the database rather than the vernacular of the problem domain. Instead of customers and orders, prisoners and bookings, or books and authors—words that describe the problem domain—you end up with tables, rows, records, connections, and the like. That is, your code refers to the database instead of conveying a representation of the problem domain. Perhaps because the code does not convey meaning relative to the solution domain, database decomposition is not considered one of the best approaches to software engineering.

You have a better option with .NET. In .NET ADO.NET are classes that can be generalized—inherited from—to extend their behaviors, adding properties and methods that convey more meaning. As a result, you can decompose the problem with the relatively easy database decomposition yet define strongly typed DataSets in the vernacular of the problem domain, and as a result convey more meaning about the solution with the code. The best part is that .NET will do most of the work for you.

There is a namespace named CodeDom in the .NET framework. The CodeDom is fully capable as a platform for implementing custom code generators. Code generators written using classes in the CodeDom can generate source code and compile executable .NET assemblies. The CodeDom has been used to write source code based on an XML Schema. (A Schema is generally thought of as a description of all or part of a database.) Further, .NET ships with an XML Schema Designer that facilitates visually defining a new Schema or inferring the Schema from an existing database. Thus, you can literally drag and drop tables onto the designer, and the IDE will generate an XML Schema. From this Schema, the designer works with the CodeDom to generate object-oriented typed DataSets. Following are examples that will walk you through the process.

  • + Share This
  • 🔖 Save To Your Account