Share via


Specifying Relations between Elements with No Nesting

When elements are not nested, no implicit relations are created. You can, however, explicitly specify relations between elements that are not nested using the msdata:Relationship annotation.

The following example shows an XML Schema in which the msdata:Relationship annotation is specified between the Order and OrderDetail elements, which are not nested. The msdata:Relationship is specified as the child element of the Schema element.

<xs:schema id="MyDataSet"  
             xmlns:xs="http://www.w3.org/2001/XMLSchema" 
             xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 <xs:element name="MyDataSet" msdata:IsDataSet="true">
  <xs:complexType>
    <xs:choice maxOccurs="unbounded">
      <xs:element name="OrderDetail">
       <xs:complexType>
         <xs:sequence>
           <xs:element name="OrderNo" type="xs:string" />
           <xs:element name="ItemNo" type="xs:string" />
         </xs:sequence>
       </xs:complexType>
      </xs:element>
      <xs:element name="Order">
       <xs:complexType>
         <xs:sequence>
           <xs:element name="OrderNumber" type="xs:string" />
           <xs:element name="EmpNumber" type="xs:string" />
         </xs:sequence>
       </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>

  </xs:element>
   <xs:annotation>
     <xs:appinfo>
       <msdata:Relationship name="OrdOrdDetailRelation"
                            msdata:parent="Order" 
                            msdata:child="OrderDetail" 
                            msdata:parentkey="OrderNumber" 
                            msdata:childkey="OrderNo"/>
     </xs:appinfo>
  </xs:annotation>
</xs:schema>

The XML Schema definition language (XSD) schema mapping process creates a DataSet with Order and OrderDetail tables and a relationship specified between these two tables.

RelationName: OrdOrderDetailRelation
ParentTable: Order
ParentColumns: OrderNumber 
ChildTable: OrderDetail
ChildColumns: OrderNo 
Nested: False

See Also

Generating DataSet Relations from XML Schema (XSD) | Mapping XML Schema (XSD) Constraints to DataSet Constraints | Data Type Support between XML Schema (XSD) Types and .NET Framework Types