Print Page | Close Window

Nested Complex Types

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=732
Printed Date: 27-Apr-2025 at 3:16pm


Topic: Nested Complex Types
Posted By: danielp37
Subject: Nested Complex Types
Date Posted: 18-Mar-2008 at 11:06pm
I am trying to use nested complex types and I believe there is a code generation error.
 
Here is what my complex types look like:
 

<ComplexType Name="AddressInfo">

  <Property Name="Street1" Type="String" MaxLength="200" />

  <Property Name="Street2" Type="String" MaxLength="200" />

  <Property Name="City" Type="String" MaxLength="200" />

  <Property Name="State" Type="String" MaxLength="200" />

  <Property Name="PostalCode" Type="String" MaxLength="200" />

  <Property Name="Country" Type="String" MaxLength="200" />

  <Property Name="DateChanged" Type="DateTime" Nullable="true" />

</ComplexType>

<ComplexType Name="ContactInfo">

  <Property Name="Address" Type="DBModel.AddressInfo" Nullable="false" />

  <Property Name="BillingAddress" Type="DBModel.AddressInfo" Nullable="false" />

  <Property Name="Phone" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="PhoneWork" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="PhoneMobile" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="PhoneFax" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="Email" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="NewEmail" Type="String" Nullable="true" MaxLength="200" />

  <Property Name="NewEmailDate" Type="DateTime" Nullable="true" />

  <Property Name="ContactNotes" Type="String" Nullable="true" MaxLength="200" />

</ComplexType>

And this results in the following generated code for the ContactInfo class:


/// <summary>Constructs any non-nullable complex types.</summary>

public ContactInfo() {

this.Address = new Address();

this.BillingAddress = new BillingAddress();

this.Phone = (String)EntityFactory.GetDefaultValue(typeof(String));

this.PhoneWork = (String)EntityFactory.GetDefaultValue(typeof(String));

this.PhoneMobile = (String)EntityFactory.GetDefaultValue(typeof(String));

this.PhoneFax = (String)EntityFactory.GetDefaultValue(typeof(String));

this.Email = (String)EntityFactory.GetDefaultValue(typeof(String));

this.NewEmail = (String)EntityFactory.GetDefaultValue(typeof(String));

this.ContactNotes = (String)EntityFactory.GetDefaultValue(typeof(String));

}

The error is when it tries to instantiate new AddressInfo classes.  Instead of using the typename of AddressInfo, it is using the fieldname of Address and BillingAddress.  I see the same thing in other places in the code where the nested complex types are instantiated.



Replies:
Posted By: kimj
Date Posted: 19-Mar-2008 at 9:37am
Yep, it does look like a code generation error.  Thanks for pointing it out, we'll log the bug report.



Print Page | Close Window