关于表关系的SQLXMLBulkLoad查询

时间:2016-09-01 16:41:56

标签: sql sqlxml bulk-load

我创建了以下架构:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="InventorAssembly"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
>
  <xsd:annotation>
    <xsd:appinfo>
      <sql:relationship name="InventorDocuments"
                        parent="Customer.Projects"
                        parent-key="Customer.ProjectID"
                        child="Projects.Documents"
                        child-key="DocumentID"
                        />
      <sql:relationship name="Properties"
                        parent="InventorDocuments"
                        parent-key="DocumentID"
                        child="InventorDocuments.Properties"
                        child-key="DocumentID"
                        />
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:element name="root" type="InventorDocumentType" sql:relationship="InventorDocuments" />

  <xsd:complexType name="ReferencedDocumentsList">
    <xsd:sequence>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element name="document" type="InventorDocumentType" minOccurs="0" maxOccurs="unbounded"/>
        <!--<xsd:element name="assembly" type="InventorAssemblyType" minOccurs="0" maxOccurs="unbounded"/>-->
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="InventorDocumentType">
    <xsd:sequence>
      <!-- added the following to see if we can nest the resultant XML under the properties and components headings. -->
      <xsd:element name="Properties" sql:is-constant="1">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="property" 
                        type="InventorPropertyType" 
                        minOccurs="0" 
                        maxOccurs="unbounded" 
                        sql:relationship="Properties"/>
          </xsd:sequence>
        </xsd:complexType>  
      </xsd:element>
      <xsd:element name="ReferencedDocuments" type="ReferencedDocumentsList" sql:is-constant="1" />
    </xsd:sequence>
    <xsd:attribute type="xsd:string" name="ID" use="required" sql:field="DocumentID"/>
    <xsd:attribute type="xsd:string" name="DocumentType" use="required" sql:field="DocumentType"/>
    <xsd:attribute type="xsd:string" name="Filename" use="required" sql:field="FileName"/>
    <xsd:attribute type="xsd:string" name="ReferencingDocument" use="optional" sql:field="ReferencingDocument"/>
    <xsd:attribute type="xsd:string" name="ParameterCount" use="optional" sql:field="ParameterCount"/>
    <xsd:attribute type="xsd:string" name="FeatureCount" use="optional" sql:field="FeatureCount"/>
    <xsd:attribute type="xsd:string" name="ConstraintCount" use="optional" sql:field="ConstraintCount"/>
    <xsd:attribute type="xsd:string" name="OccurrenceCount" use="optional" sql:field="OccurrenceCount"/>
  </xsd:complexType>

  <xsd:complexType name="InventorPropertyType">
    <xsd:attribute type="xsd:string" name="ParentDocumentID" sql:field="DocumentID"/>
    <xsd:attribute type="xsd:string" name="Name" sql:field="PropertyName"/>
    <xsd:attribute type="xsd:string" name="Value" sql:field="PropertyValue"/>
    <xsd:attribute type="xsd:string" name="Type" sql:field="PropertyType"/>
    <xsd:attribute type="xsd:integer" name="PropertyID" sql:field="PropertyID"/>
  </xsd:complexType>
 </xsd:schema>

这让我可以创建这种结构化XML文件:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="1" DocumentType="kAssemblyDocumentObject" Filename="C:\GDR518.iam" ReferencingDocument="Top Level Assembly" ParameterCount="63" FeatureCount="0" ConstraintCount="38" OccurrenceCount="276">
  <Properties>
    <property ParentDocumentID="1" Name="Description" Value="" PropertyID="ac262fc9-edaf-4570-9b98-42fcb8e1cee9" />
    <property ParentDocumentID="1" Name="Part Number" Value="GDR518" Type="String" PropertyID="7b0a8ec2-0b69-40bc-8ae5-d63304ca9378" />
  </Properties>
  <ReferencedDocuments>
    <document ID="4" DocumentType="kAssemblyDocumentObject" Filename="C:\WLD-HF-004.iam" ReferencingDocument="C:\GDR518.iam" ParameterCount="0" FeatureCount="0" ConstraintCount="0" OccurrenceCount="0">
      <Properties>
        <property ParentDocumentID="4" Name="Description" Value="" PropertyID="846183dd-cc3f-4e24-8e86-dc785fbbab28" />
      </Properties>
      <ReferencedDocuments />
    </document>
    <document ID="12" DocumentType="kAssemblyDocumentObject" Filename="C:\GDR520.iam" ReferencingDocument="C:\GDR518.iam" ParameterCount="59" FeatureCount="0" ConstraintCount="42" OccurrenceCount="146">
      <Properties>
        <property ParentDocumentID="12" Name="Description" Value="" PropertyID="7f6c2de8-dcb6-471c-aa90-8d69b02e61f1" />
      </Properties>
      <ReferencedDocuments>
        <document ID="13" DocumentType="kAssemblyDocumentObject" Filename="C:\WLD-HF-009.iam" ReferencingDocument="C:\GDR520.iam" ParameterCount="0" FeatureCount="0" ConstraintCount="0" OccurrenceCount="0">
          <Properties>
            <property ParentDocumentID="13" Name="Description" Value="" PropertyID="436ba462-6d54-433c-a435-197bdd4089d8" />
          </Properties>
          <ReferencedDocuments />
        </document>
          <Properties>
            <property ParentDocumentID="18" Name="Description" Value="" PropertyID="5ced04aa-ec51-4060-a8eb-d23905e694ed" />
          </Properties>
        </document>
      </ReferencedDocuments>
    </document>
  </ReferencedDocuments>
</root>

一切正常,但是当我尝试使用SQLXMLBulkLoad.Execute将上面的XML数据拉入我的空数据库时,我收到以下错误:

  

架构:“属性”关系的父/子表   不匹配。

我已经尝试了我能想到的所有变化,但是没有用。

任何人都可以提供任何指示吗?

提前致谢,

亚历。

0 个答案:

没有答案