Fighting with typed data set and child relation

  • Thread starter Thread starter olympus_mons
  • Start date Start date
O

olympus_mons

Hi,

the problem I have, is that the GetChildRows() method does not work. I
get error:
Unable to cast object of type 'DEBTORRow[]' to type 'DEBTOR_NACERow[]'
From the database (oracle10gR2 using Oracle .NET provider v2.0.50727)
I generated a typed dataset in VS2005. There is a 1:n-relation between
DEBTOR and DEBTOR_NACE. Using the object browser I can see that class
DEBTORRow has a GetChildRows method. The VS generated the follwoing
code from the data set designer:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public DEBTOR_NACERow[] GetDEBTOR_NACERows() {
return ((DEBTOR_NACERow[])
(base.GetChildRows(this.Table.ChildRelations["R_DEBTOR_NACE_DEBTOR"])));
}


So there are number of things I don't understand here:

(1) the code above looks correct; why do I get the error mentioned
above when I call GetChildRows() like this:
DEBTOR_NACERow[] drNaceRows = drDebtor.GetDEBTOR_NACERows();
Note that drDebtor is of type DEBTORRow

(2) If I check the code generated by the data set designer, I can see
that this relation is added to the relations collection of the data
set class in InitClass() method:

this.relationR_DEBTOR_NACE_DEBTOR = new
System.Data.DataRelation("R_DEBTOR_NACE_DEBTOR", new
System.Data.DataColumn[] {
this.tableDEBTOR.DEBTOR_SEQColumn}, new
System.Data.DataColumn[] {
this.tableDEBTOR_NACE.DEBTOR_SEQColumn},
false);
this.Relations.Add(this.relationR_DEBTOR_NACE_DEBTOR);

I expected that this relation is also added to the relations
collection of the data table for DEBTOR. But it is not. So how can
this.Table.ChildRelations["R_DEBTOR_NACE_DEBTOR"] work at all in
GetDEBTOR_NACERows()?

Am I making something wrong or is the code generated by the data set
designer wrong?

Thanks,
Stefan (C# newbie)
 
Hi again,

I worked arround my problem by writing code (and not using the code
generated by VS' data set designer). However I still wish to find out
what is really the cause for the problem: is i me and my still limited
VS/C# knowledge or is it VS?

If anybody is willing to help me please contact me by private email
and I will provide a very small sample (SQL script to create simple
parent and child table with some data and C# console application). I
will also provide the DataSet.Designer.cs file generated from VS' data
set designer.

Thanks,
Stefan
 
Back
Top