首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NDBUnit架构错误

NDBUnit架构错误
EN

Stack Overflow用户
提问于 2011-03-17 22:07:00
回答 2查看 644关注 0票数 1

我已经寻找了很长一段时间的答案,但没有任何运气。

我正在为我的测试数据使用NDbUnit,我希望能够自动生成我的XSD文件。我不希望每次向类添加新属性时都必须重新生成XSD文件。因此,我的计划是使用XsdDataContractExporter类自动生成XSD文件,因为我的一些类包含IList,而我在使用xml序列化程序时遇到了一些错误。

这是我到目前为止得到的代码:

代码语言:javascript
复制
XsdDataContractExporter exporter = new XsdDataContractExporter();
exporter.Export(typeof(Supplier));

//XmlQualifiedName xmlQualifiedName = exporter.GetRootElementName(typeof(Supplier));
foreach (XmlSchema schema in exporter.Schemas.Schemas()) {
    XmlWriter writer = XmlWriter.Create(String.Format(@"..\..\data\{0}.xsd", GetSchemaName(schema)), new XmlWriterSettings() {
    ConformanceLevel = ConformanceLevel.Auto,
    Encoding = Encoding.UTF8,
    Indent = true,
    OmitXmlDeclaration = false
});

foreach (XmlSchemaObject include in schema.Includes) {
    XmlSchemaImport importedSchema = include as XmlSchemaImport;
    if (importedSchema != null) {
        ArrayList lst = new ArrayList(exporter.Schemas.Schemas(importedSchema.Namespace));
        XmlSchema actualImportedSchema = (XmlSchema)lst[0];
        importedSchema.Schema = actualImportedSchema;
        importedSchema.SchemaLocation = Path.GetFullPath(String.Format(@"..\..\data\{0}.xsd", GetSchemaName(actualImportedSchema)));
    }
}
schema.Write(writer);
writer.Close();
}
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"..\..\data\business.model.supplier.xsd");

问题是我在读取模式时遇到一个错误,即:

代码语言:javascript
复制
failed: System.InvalidOperationException : Nested table 'SupplierCategory' which inherits its namespace cannot have multiple parent tables in different namespaces.

底线是,我希望使用一个类型动态生成的XSD文件,以便与NDBUnit一起使用,以便用测试数据填充我的数据库。这是正确的方法吗?这是生成的模式,并给出了错误:

供应商:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/Business.Model.Supplier" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Business.Model.Supplier" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="C:\dev\skeleton\branches\dev\src\testconsole\data\business.model.supplier.category.xsd" namespace="http://schemas.datacontract.org/2004/07/Business.Model.Supplier.Category" />
  <xs:import schemaLocation="C:\dev\skeleton\branches\dev\src\testconsole\data\arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
  <xs:complexType name="Supplier">
    <xs:sequence>
      <xs:element minOccurs="0" name="Categories" nillable="true" xmlns:q1="http://schemas.datacontract.org/2004/07/Business.Model.Supplier.Category" type="q1:ArrayOfSupplierCategory" />
      <xs:element minOccurs="0" name="Comments" nillable="true" xmlns:q2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q2:ArrayOfstring" />
      <xs:element minOccurs="0" name="Description" nillable="true" type="xs:string" />
      <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="Supplier" nillable="true" type="tns:Supplier" />
</xs:schema>

SupplierCategory:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/Business.Model.Supplier.Category" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Business.Model.Supplier.Category" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="ArrayOfSupplierCategory">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="SupplierCategory" nillable="true" type="tns:SupplierCategory" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="ArrayOfSupplierCategory" nillable="true" type="tns:ArrayOfSupplierCategory" />
  <xs:complexType name="SupplierCategory">
    <xs:sequence>
      <xs:element minOccurs="0" name="Description" nillable="true" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="SupplierCategory" nillable="true" type="tns:SupplierCategory" />
</xs:schema>

任何建议都是很棒的!Thx,法兰克

EN

回答 2

Stack Overflow用户

发布于 2011-03-18 21:48:27

请看这篇文章Getting XML Schema from MS SQL Database中的建议列表(特别是投票最多的答案),但也要注意我使用MyGeneration来实现同样的事情的建议。

票数 0
EN

Stack Overflow用户

发布于 2021-11-11 12:17:58

这也是我后来一直面临的问题,因为我们在项目中使用NDbUnit进行集成测试-最终得到了一个定制库,它不需要单独定义模式,它自己从数据库中读取它。库是Reseed

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5340154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档