S
Stephen Walch
I am a schema "newbie" but I think I pretty much understand how schemas and
typed DataSets are supposed to work. Now I have a case where I am loading a
flat (denormalized) table into a dataset with a not-so-flat schema.
For example, lets say I was using the Employees table from the Northwind
database but I wanted to load a typed dataset in which the LastName and
FirstName fields were organized into a complex type called "EmpName". I
tried simply adding a complex type to my XSD file (creating using VS.NET's
Generate DataSet function):
<xs:complexType name="EmpName">
<xs:sequence>
<xs:element name="LastName" type="xs:string" minOccurs="0" />
<xs:element name="FirstName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
and I replaced the FirstName and LastName elements with a single Name
element
<xs:element name="Name" type="mstns:EmpName" />
A side effect of doing this is that my generated typed dataset how has an
additional table called "Name":
private void InitClass() {
....
this.tableName = new NameDataTable();
this.Tables.Add(this.tableName);
ForeignKeyConstraint fkc;
fkc = new ForeignKeyConstraint("Employees_Name", new DataColumn[] {
this.tableEmployees.EmployeeIDColumn}, new DataColumn[] {
this.tableName.EmployeeIDColumn});
this.tableName.Constraints.Add(fkc);
....
}
If this is the right way to model a nested ComplexType, fine. But when I
try to fill the dataset from my "flat" table, the Name table in the dataset
is not filled. I tried to find a tweak the TableMappings for my data
adapter, but no luck. It looks like that data adapter will only fill the
Name table if there is a Name table in the source database.
Can you suggest a way to accomplish what I want?
Thanks,
Steve
typed DataSets are supposed to work. Now I have a case where I am loading a
flat (denormalized) table into a dataset with a not-so-flat schema.
For example, lets say I was using the Employees table from the Northwind
database but I wanted to load a typed dataset in which the LastName and
FirstName fields were organized into a complex type called "EmpName". I
tried simply adding a complex type to my XSD file (creating using VS.NET's
Generate DataSet function):
<xs:complexType name="EmpName">
<xs:sequence>
<xs:element name="LastName" type="xs:string" minOccurs="0" />
<xs:element name="FirstName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
and I replaced the FirstName and LastName elements with a single Name
element
<xs:element name="Name" type="mstns:EmpName" />
A side effect of doing this is that my generated typed dataset how has an
additional table called "Name":
private void InitClass() {
....
this.tableName = new NameDataTable();
this.Tables.Add(this.tableName);
ForeignKeyConstraint fkc;
fkc = new ForeignKeyConstraint("Employees_Name", new DataColumn[] {
this.tableEmployees.EmployeeIDColumn}, new DataColumn[] {
this.tableName.EmployeeIDColumn});
this.tableName.Constraints.Add(fkc);
....
}
If this is the right way to model a nested ComplexType, fine. But when I
try to fill the dataset from my "flat" table, the Name table in the dataset
is not filled. I tried to find a tweak the TableMappings for my data
adapter, but no luck. It looks like that data adapter will only fill the
Name table if there is a Name table in the source database.
Can you suggest a way to accomplish what I want?
Thanks,
Steve