草庐IT

c# - 为什么 ReadXmlSchema 创建额外的 "ID"列

coder 2024-06-27 原文

给定一个 XSD 文件,像下面这样的代码会在返回的数据集中的两个数据表中产生一个额外的(不需要的)列。

ds.ReadXmlSchema(s);

两个 DataTable 都有一个 Order_Id 列;其他列与 XSD 完美匹配。

有没有人以前见过这个?

XSD 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="Order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Item" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType msdata:AutoIncrement="false">
            <xs:attribute name="itemId" type="xs:unsignedInt" />
            <xs:attribute name="stockCode" type="xs:string" />
            <xs:attribute name="stockCodeType" type="xs:string" />
            <xs:attribute name="Quantity" type="xs:unsignedLong" />
            <xs:attribute name="ProductIdX" type="xs:unsignedInt" />
            <xs:attribute name="legalEntity" type="xs:string" />
            <xs:attribute name="countryOfIssue" type="xs:string" />
            <xs:attribute name="branchSystem" type="xs:string" />
            <xs:attribute name="accountId" type="xs:string" />
            <xs:attribute name="settlementDate" type="xs:string" />
            <xs:attribute name="tradeDate" type="xs:string" />
            <xs:attribute name="partyCode" type="xs:string" />
            <xs:attribute name="userId" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="OrderId" type="xs:unsignedInt" />
      <xs:attribute name="StrategyId" type="xs:string" />
      <xs:attribute name="ActivityId" type="xs:string" />
    </xs:complexType>
  </xs:element>
</xs:schema>

最佳答案

你应该看看Deriving DataSet Relational Structure from XML Schema (XSD) .本文指出

In general, for each complexType child element of a schema element, a table is generated in the DataSet. The table structure is determined by the definition of the complex type.

...

However, a table is only created for a top-level complexType element when the complexType element is nested inside another complexType element, in which case the nested complexType element is mapped to a DataTable within the DataSet.

基本上在这种情况下 ReadXML(...) 将创建两个表

  1. 订单
  2. 项目

由于 Item complexType 嵌套在 Order complexType 中,这两个表之间的关系也会生成。为了能够创建此关系,将包含一个新列 Order_id

编辑

进一步查看Generating DataSet Relations for XSD .在这篇文章中,您会发现:

The msdata:Relationship annotation allows you to explicitly specify parent-child relationships between elements in the schema that are not nested. The following example shows the structure of the Relationship element.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="Order">
     ... your definition goes here!
 </xs:element>
 <xs:annotation>
   <xs:appinfo>
     <msdata:Relationship name="OrderItemRelation"
      msdata:parent="Order"
      msdata:child="Item" 
      msdata:parentkey="OrderID"
      msdata:childkey="ANY_COLUMN_IN_NESTED_COMPLEX_TYPE"/>
   </xs:appinfo>
  </xs:annotation>
</xs:schema>

因此您可以修改将使用的列以将内部复杂类型引用到外部复杂类型,但您不能阻止此功能!

关于c# - 为什么 ReadXmlSchema 创建额外的 "ID"列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12572439/

有关c# - 为什么 ReadXmlSchema 创建额外的 "ID"列的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  3. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  4. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  5. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  6. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  7. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  8. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  9. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  10. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

随机推荐