Udostępnij za pośrednictwem


Specify Relations Between Elements with No Nesting (ADO.NET)

When elements are not nested, no implicit relations are created. You can, however, explicitly specify relations between elements that are not nested by 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 annotation 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="OrdOrderDetailRelation"
                            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, as shown below.

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

See Also

Concepts

Generating DataSet Relations from XML Schema (XSD)

Other Resources

Mapping XML Schema (XSD) Constraints to DataSet Constraints

ADO.NET Managed Providers and DataSet Developer Center