I have a basic scenario working that utilizes XSD-generated classes, but I'm struggling with a definition for a nested strongly-typed array. Here's what my class looks like:
Code:
namespace com.test {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
[System.Xml.Serialization.XmlRootAttribute("User", Namespace="urn:com.brightharbour.schema", IsNullable=false)]
public partial class UserType {
private int userIdField;
private string userNameField;
private string nameField;
private string emailField;
private AliasType[] aliasField;
/// <remarks/>
public int UserId {
get {
return this.userIdField;
}
set {
this.userIdField = value;
}
}
/// <remarks/>
public string UserName {
get {
return this.userNameField;
}
set {
this.userNameField = value;
}
}
/// <remarks/>
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
public string Email {
get {
return this.emailField;
}
set {
this.emailField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Alias")]
public AliasType[] Alias {
get {
return this.aliasField;
}
set {
this.aliasField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
public partial class AliasType {
private string typeField;
private string firstField;
private string middleField;
private string lastField;
private AddressType[] addressField;
/// <remarks/>
public string Type {
get {
return this.typeField;
}
set {
this.typeField = value;
}
}
/// <remarks/>
public string First {
get {
return this.firstField;
}
set {
this.firstField = value;
}
}
/// <remarks/>
public string Middle {
get {
return this.middleField;
}
set {
this.middleField = value;
}
}
/// <remarks/>
public string Last {
get {
return this.lastField;
}
set {
this.lastField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Address")]
public AddressType[] Address {
get {
return this.addressField;
}
set {
this.addressField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:com.brightharbour.schema")]
public partial class AddressType {
private string streetField;
private string cityField;
private string stateField;
private string zipField;
/// <remarks/>
public string Street {
get {
return this.streetField;
}
set {
this.streetField = value;
}
}
/// <remarks/>
public string City {
get {
return this.cityField;
}
set {
this.cityField = value;
}
}
/// <remarks/>
public string State {
get {
return this.stateField;
}
set {
this.stateField = value;
}
}
/// <remarks/>
public string Zip {
get {
return this.zipField;
}
set {
this.zipField = value;
}
}
}
}
Here's my current mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="com.test.UserType, ConsoleApplication1" table="Sample_User">
<id name="UserId" column="UserId" type="Int32">
<generator class="identity" />
</id>
<property name="UserName" column="UserName" type="String" length="40"/>
<property name="Name" type="String" length="20"/>
<property name="Email" type="String" length="40"/>
<array name="Alias" table="Sample_Name" cascade="all-delete-orphan">
<key column="UserId"/><!--Matching key in the child table that links to the parent-->
<index column="AliasIndex" /><!-- Column in child table used to hold the index (0-based) for the array-->
<composite-element class="com.test.AliasType, ConsoleApplication1">
<!-- properties of the child class -->
<property name="Type" type="String"/>
<property name="First" type="String"/>
<property name="Middle" type="String"/>
<property name="Last" type="String"/>
</composite-element>
</array>
</class>
</hibernate-mapping>
Now, this works great for mapping the UserType and AliasType array, but I can't figure out how to tackle the mapping of the AddressType to each AliasType instance. I'm sure this is easily addressed, but I cannot seem to find a way to map everything just right.
Many thanks.