Map Relations Specified for Nested Elements

A schema can include an msdata:Relationship annotation to explicitly specify the mapping between any two elements in the schema. The two elements specified in msdata:Relationship can be nested in the schema, but do not have to be. The mapping process uses msdata:Relationship in the schema to generate the primary key/foreign key relationship between the two columns.

The following example shows an XML Schema in which the OrderDetail element is a child element of Order. The msdata:Relationship identifies this parent-child relationship and specifies that the OrderNumber column of the resulting Order table is related to the OrderNo column of the resulting OrderDetail table.

<xs:schema id="MyDataSet" xmlns=""
<xs:element name="MyDataSet" msdata:IsDataSet="true">  
  <xs:choice maxOccurs="unbounded">  
   <xs:element name="Order">  
       <xs:element name="OrderNumber" type="xs:string" />  
       <xs:element name="EmpNumber" type="xs:string" />  
       <xs:element name="OrderDetail">  
            <msdata:Relationship name="OrdODRelation"
             <xs:element name="OrderNo" type="xs:string" />  
             <xs:element name="ItemNo" type="xs:string" />  

The XML Schema mapping process creates the following in the DataSet:

  • An Order and an OrderDetail table.

    Order(OrderNumber, EmpNumber)  
    OrderDetail(OrderNo, ItemNo)  
  • A relationship between the Order and OrderDetail tables. The Nested property for this relationship is set to True because the Order and OrderDetail elements are nested in the schema.

    ParentTable: Order  
    ParentColumns: OrderNumber
    ChildTable: OrderDetail  
    ChildColumns: OrderNo
    RelationName: OrdODRelation  
    Nested: True  

The mapping process does not create any constraints.

See also