简体   繁体   中英

Changing dataset XSD in VS2010 generates code inheriting from DataTable instead of TypedTableBase<Type>

The current XSD is :

<xs:element name="Country">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="code" type="xs:string" />
            <xs:element name="name" type="xs:string" />
            <xs:element name="diallingcode" type="xs:int" />
            <xs:element name="displayOrder" type="xs:nonNegativeInteger" />
        </xs:sequence>
    </xs:complexType>
    <xs:key name="countryKey1">
        <xs:selector xpath="." />
        <xs:field xpath="mstns:code" />
    </xs:key>
</xs:element>

And the generated class is:

[global::System.Serializable()]
    [global::System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedTableSchema")]
    public partial class CountryDataTable : global::System.Data.TypedTableBase<CountryRow> {

As soon as I modified the XSD, adding a new field. The generated class changes to:

[global::System.Serializable()]
    [global::System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedTableSchema")]
    public partial class CountryDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable {

This last code breaks some Linq queries that are using the dataset.

Does anyone know what the problem could be?

The generation of code is not behaving properly yet (when updating an existing XSD). The way I've found to sort out the problem is deleting Dataset.Designer.cs file (or just renaming it) every time I want to make a change in the XSD. When the file is being generated from the scratch, the code is generated properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM