XML AND DATA ACCESS INTEGRATION 275 7.2.1 Defining a DataSets Schema In many ways, the ADO.NET DataSet class mimics a relational database. Each DataSet instance contains a schemathe set of tables, columns, and relation- shipsas  does  a  relational  database.  You  can  define  the  schema  of  an ADO.NET DataSet instance in at least four ways: " Use the DataSet APIs directly to create DataTable s, DataColumn s, and DataRelation s. This approach is similar in concept to using DDL in relational databases. " Infer  the  schema  using  database  metadata  through  a DataAdapter class. Using DataAdapter.Fill creates tables and columns match- ing  the  metadata  from DataAdapter s SelectCommand .  For  this  to work, DataAdapter s MissingSchemaAction property must be set to Add or AddWithKey . " Define the desired DataSet schema using XSD (XML Schema Definition language), and use DataSet.ReadXmlSchema to load the schema def- inition  into  the DataSet .  The  schema  may  not  use  nonrelational  data definition styles, or else ReadXmlSchema will throw an error. " Use DataSet.InferXmlSchema . The DataSet class will use a set of schema inference rules to infer a DataSet schema from a single XML document. You can also define DataSet s schema incrementally by using a combina- tion of these methods, as shown in Figure 71. Note that in each case the result is the same: DataSet contains a set of tables, columns, constraints, and rela- tionships that comply with relational rules. DataSet is  not  aware  of  the  source  of  the  schema,  and  therefore  any method of defining the schema works as well as any other. For example, lets de- fine a simple schema that includes a customers table, an orders table, and a one-to-many relationship between customers and orders. Listing 71 uses the four  schema-definition  methods  to  accomplish  this.  Note  that,  when  using DataSet or DataAdapter , you need additional code to set up the relationship, whereas  in  the  case  of  XML  schema  or  document  inference,  this  information may be available in the schema or exemplar document. 5132_ch07  Page 275  Thursday, April 25, 2002  3:09 PM