Problem with Element based on a ComplexType based on a ComplexType

Mar 2, 2012 at 1:12 PM

Hi,

I'm having a problem with a schema I've written, here's an example which replicates the problem:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="www.test.com/Subs" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="www.test.com/Subs" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:complexType name="CommonFields">
		<xs:attribute name="IDField" type="xs:int" use="required"/>
	</xs:complexType>
	<xs:complexType name="BaseType">
		<xs:complexContent>
			<xs:extension base="CommonFields">
				<xs:sequence>
					<xs:element name="Name" type="xs:string"/>
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:element name="Base" type="BaseType"/>
	<xs:element name="Hamster" substitutionGroup="Base">
		<xs:complexType>
			<xs:complexContent>
				<xs:extension base="BaseType">
					<xs:sequence>
						<xs:element name="ExtendOneFields" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
					</xs:sequence>
				</xs:extension>
			</xs:complexContent>
		</xs:complexType>
	</xs:element>
	<xs:element name="Horse" substitutionGroup="Base">
		<xs:complexType>
			<xs:complexContent>
				<xs:extension base="BaseType">
					<xs:sequence>
						<xs:element name="BreederName" type="xs:string"/>
						<xs:element name="RacesWon" type="xs:int"/>
					</xs:sequence>
				</xs:extension>
			</xs:complexContent>
		</xs:complexType>
	</xs:element>
</xs:schema>

The problem is this, any class wrapper build by Linq To Xsd for an Element based on a ComplexType which is in turn based on a ComplexType does not implement wrapper properties for the properties of the lowest complex type.

Specifically for the above example, the class wrapper for "Base" (based on BaseType, an extension of CommonFields) does not contain a property wrapper for the IDField attribute in CommonFields, it's most distant ancestor. It appears whatever code generates the property wrappers for non-inherited types (element based on complexType) is only adding wrappers for the top most type (BaseType), not the types it in turn may be based on (CommonFields)

As a workaround, I believe I can manually add the property wrappers using partial classes.

Version of Linq To Xsd used is 1.1.0

Regards,

James.

Mar 2, 2012 at 1:16 PM

Example of the workaround:

namespace www.test.com.Subs
{
    public partial class Base
    {
        /// <summary>
        /// <para>
        /// Occurrence: optional
        /// </para>
        /// <para>
        /// Regular expression: (IDField?)
        /// </para>
        /// </summary>
        public global::System.String IDFIeld
        {
            get
            {
                return this.ContentField.IDFIeld;
            }
            set
            {
                this.ContentField.IDFIeld= value;
            }
        }
    }
}