What I have is a table (Clients) that I have created 2 relationships (FKs in
DB) pointing to another table (Setups). I have a BillFrom Client and a BillTo
Client. I get a compile error: InvoicesTDS.cs(2839): The class
'BusinessEntities.InvoicesTDS.Setup' already contains a definition for
'Client'. If I remove the relationship for BillTo Client, everything compiles
just fine. I have also found that if I have both relationships present and
remove this: 'codegen:typedParent="InvoiceClient"' from the Dataset XML
relationship, it compiles. However, I have now broken things because codegen
will not generate the underlying code as needed.

RE: Typed Dataset Error - 2 FKs from same table by lukezhan

lukezhan
Thu Sep 01 22:28:44 CDT 2005

Hello,

BillFrom Client and a BillTo Client are a datatable also define in the
dataset? Or just objects in your application? Does the two relationships
share a PK on setup?

Luke


RE: Typed Dataset Error - 2 FKs from same table by Glen

Glen
Fri Sep 02 06:46:02 CDT 2005

Hi,
Thanks for responding. In the DB: The BillFrom and BillTo ids are PKs in the
Clients table, and they are FKs in the Setup table. I want to mimic this
behavior in the Typed Dataset. I'm not sure what "share a PK on setup"
means. Since they are PKs in Clients (ClientId) they have to be different
names in Setup.

"[MSFT]" wrote:

> Hello,
>
> BillFrom Client and a BillTo Client are a datatable also define in the
> dataset? Or just objects in your application? Does the two relationships
> share a PK on setup?
>
> Luke
>
>

RE: Typed Dataset Error - 2 FKs from same table by lukezhan

lukezhan
Mon Sep 05 01:26:42 CDT 2005

Hello,

I am not sure I have understood this correctly, I create such a dataset,
but I cannot find the error:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Dataset2" targetNamespace="http://tempuri.org/Dataset2.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Dataset2.xsd"
xmlns:mstns="http://tempuri.org/Dataset2.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Dataset2" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Setup">
<xs:complexType>
<xs:sequence>
<xs:element name="Sid" type="xs:integer" minOccurs="0" />
<xs:element name="FromID" type="xs:integer" minOccurs="0" />
<xs:element name="ToID" type="xs:integer" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Client">
<xs:complexType>
<xs:sequence>
<xs:element name="BillFrom" type="xs:integer" minOccurs="0" />
<xs:element name="BillTo" type="xs:integer" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="Dataset2Key1">
<xs:selector xpath=".//mstns:Setup" />
<xs:field xpath="mstns:Sid" />
</xs:key>
<xs:key name="FromKey">
<xs:selector xpath=".//mstns:Client" />
<xs:field xpath="mstns:BillFrom" />
</xs:key>
<xs:key name="ToKey">
<xs:selector xpath=".//mstns:Client" />
<xs:field xpath="mstns:BillTo" />
</xs:key>
<xs:keyref name="ClientSetup" refer="FromKey">
<xs:selector xpath=".//mstns:Setup" />
<xs:field xpath="mstns:FromID" />
</xs:keyref>
<xs:keyref name="ClientSetup1" refer="ToKey">
<xs:selector xpath=".//mstns:Setup" />
<xs:field xpath="mstns:ToID" />
</xs:keyref>
</xs:element>
</xs:schema>

If this is different from yous, can you post your schema here?

Luke


RE: Typed Dataset Error - 2 FKs from same table by Glen

Glen
Tue Sep 06 07:34:01 CDT 2005

I created a sample dataset without all the columns (address, contacts etc).

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="SampleTDS" targetNamespace="http://tempuri.org/SampleTDS.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/SampleTDS.xsd"
xmlns:mstns="http://tempuri.org/SampleTDS.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="SampleTDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Clients" codegen:typedName="Client"
codegen:typedPlural="Clients">
<xs:complexType>
<xs:sequence>
<xs:element name="ClientId" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="ClientCode" type="xs:string" minOccurs="0" />
<xs:element name="ClientName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Setups" codegen:typedName="Setup"
codegen:typedPlural="Setups">
<xs:complexType>
<xs:sequence>
<xs:element name="SetupId" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="BillFromClientId" type="xs:int" minOccurs="0" />
<xs:element name="BillToClientId" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="SampleTDSKey1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Clients" />
<xs:field xpath="mstns:ClientId" />
</xs:key>
<xs:key name="SampleTDSKey2" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Setups" />
<xs:field xpath="mstns:SetupId" />
</xs:key>
<xs:keyref name="ClientsSetups" refer="SampleTDSKey1"
codegen:typedParent="Client" codegen:typedChildren="GetBillFromSetups">
<xs:selector xpath=".//mstns:Setups" />
<xs:field xpath="mstns:BillFromClientId" />
</xs:keyref>
<xs:keyref name="ClientsSetups1" refer="SampleTDSKey1"
codegen:typedParent="Client" codegen:typedChildren="GetBillToSetups">
<xs:selector xpath=".//mstns:Setups" />
<xs:field xpath="mstns:BillToClientId" />
</xs:keyref>
</xs:element>
</xs:schema>

Thanks,
Glen

RE: Typed Dataset Error - 2 FKs from same table by lukezhan

lukezhan
Wed Sep 07 00:37:18 CDT 2005

Hello Glen,

After study your schema, I found the problem should be

<xs:keyref name="ClientsSetups" refer="SampleTDSKey1"
codegen:typedParent="Client" codegen:typedChildren="GetBillFromSetups">
<xs:selector xpath=".//mstns:Setups" />
<xs:field xpath="mstns:BillFromClientId" />
</xs:keyref>
<xs:keyref name="ClientsSetups1" refer="SampleTDSKey1"
codegen:typedParent="Client" codegen:typedChildren="GetBillToSetups">
<xs:selector xpath=".//mstns:Setups" />
<xs:field xpath="mstns:BillToClientId" />
</xs:keyref>

On the two relationships, you use a duplicated codegen:typedParent, this
will force the code generated from the schema have two properties with
duplicated name "Client". Just change one of them to
codegen:typedParent="Client1"

Luke


RE: Typed Dataset Error - 2 FKs from same table by Glen

Glen
Wed Sep 07 08:22:03 CDT 2005

Luke,
That worked! Thanks for your help. Using the codegen stuff makes life ALOT
easier and I was a little bummed when this didn't work. I believed that the
"typedParent" had to refer a valid codegen object. That is why I never tried
changing the name.

I am posting this to say it worked and also to tell what the effect of the
name change was. By using codegen, lots of helper code is created. If you use
FKs in the dataset, you have to set "Parent" rows. This is usually a very
simple name based on the "typedParent." In our example, it would have been
"ClientRow." Yet since we have 2 FKs (and the name change), codegen created
the "Parent" row object names as "ClientRowByClientSetups" and
"ClientRowByClientSetups1."

All functionality is the same, you just need to watch out for the different
name.