Hi everybody!

I've stumbled across a funny behaviour of a typed dataset in a new
application of mine. Some how the generated code gives me a Invalid Cast
Exception.

I've reproduced the behaviour as follows.
I've created a database "test160106", I've created the table "Parent" with
two columns (column 1: ID int, column 2: nvarchar name) and a table "Child"
with three columns (column 1: ID int, column 2: nvarchar name, column 3: int
ParentID). I also added the relation between ParentID and Parent table.)

I added a new data connection pointing to this database and let it create my
datasets.

Now I use the following code that should me give me all child rows belonging
to a parent.


test160106DataSetTableAdapters.ParentTableAdapter _pta = new
Test160106.test160106DataSetTableAdapters.ParentTableAdapter();

foreach (test160106DataSet.ChildRow _childRow in
_pta.GetData().FindByID(1).GetChildRows())

{

Console.Write(String.Format("{0}: {1}", _childRow.ID, _childRow.Name));

}

Console.ReadLine();

When executing this code, it gives me an Invalid Cast Exception (Unable to
cast object of type 'ParentRow[]' to type 'ChildRow[]'.), which comes from
the generated code:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]

public ChildRow[] GetChildRows() {

return
((ChildRow[])(base.GetChildRows(this.Table.ChildRelations["FK_Child_Parent"])));

}


Can anyone reproduce this? If so, is it a bug or am I doing someting I
shouldn't be?

Any help appreciated.

(originally posted this on C9
http://channel9.msdn.com/ShowPost.aspx?PostID=155801#155801, no help there,
so I tried here)

Re: Typed Datasets - GetChildRows (Bug or am I doing something wrong?) by Miha

Miha
Sun Feb 05 12:47:58 CST 2006

Are you sure that relation in dataset is set correctly?
(dumb question)

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Gidion" <Gidion@discussions.microsoft.com> wrote in message
news:B79E5F75-1A92-4BF1-AEE7-952D1E353AF5@microsoft.com...
> Hi everybody!
>
> I've stumbled across a funny behaviour of a typed dataset in a new
> application of mine. Some how the generated code gives me a Invalid Cast
> Exception.
>
> I've reproduced the behaviour as follows.
> I've created a database "test160106", I've created the table "Parent" with
> two columns (column 1: ID int, column 2: nvarchar name) and a table
> "Child"
> with three columns (column 1: ID int, column 2: nvarchar name, column 3:
> int
> ParentID). I also added the relation between ParentID and Parent table.)
>
> I added a new data connection pointing to this database and let it create
> my
> datasets.
>
> Now I use the following code that should me give me all child rows
> belonging
> to a parent.
>
>
> test160106DataSetTableAdapters.ParentTableAdapter _pta = new
> Test160106.test160106DataSetTableAdapters.ParentTableAdapter();
>
> foreach (test160106DataSet.ChildRow _childRow in
> _pta.GetData().FindByID(1).GetChildRows())
>
> {
>
> Console.Write(String.Format("{0}: {1}", _childRow.ID, _childRow.Name));
>
> }
>
> Console.ReadLine();
>
> When executing this code, it gives me an Invalid Cast Exception (Unable to
> cast object of type 'ParentRow[]' to type 'ChildRow[]'.), which comes from
> the generated code:
>
> [System.Diagnostics.DebuggerNonUserCodeAttribute()]
>
> public ChildRow[] GetChildRows() {
>
> return
> ((ChildRow[])(base.GetChildRows(this.Table.ChildRelations["FK_Child_Parent"])));
>
> }
>
>
> Can anyone reproduce this? If so, is it a bug or am I doing someting I
> shouldn't be?
>
> Any help appreciated.
>
> (originally posted this on C9
> http://channel9.msdn.com/ShowPost.aspx?PostID=155801#155801, no help
> there,
> so I tried here)



Re: Typed Datasets - GetChildRows (Bug or am I doing something wro by Gidion

Gidion
Sun Feb 05 14:36:27 CST 2006

Yes it is correct. (the first thing I checked.)

In the example above and in the real example the relation was correct.

"Miha Markic [MVP C#]" wrote:

> Are you sure that relation in dataset is set correctly?
> (dumb question)
>
> --
> Miha Markic [MVP C#]
> RightHand .NET consulting & development www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>
> "Gidion" <Gidion@discussions.microsoft.com> wrote in message
> news:B79E5F75-1A92-4BF1-AEE7-952D1E353AF5@microsoft.com...
> > Hi everybody!
> >
> > I've stumbled across a funny behaviour of a typed dataset in a new
> > application of mine. Some how the generated code gives me a Invalid Cast
> > Exception.
> >
> > I've reproduced the behaviour as follows.
> > I've created a database "test160106", I've created the table "Parent" with
> > two columns (column 1: ID int, column 2: nvarchar name) and a table
> > "Child"
> > with three columns (column 1: ID int, column 2: nvarchar name, column 3:
> > int
> > ParentID). I also added the relation between ParentID and Parent table.)
> >
> > I added a new data connection pointing to this database and let it create
> > my
> > datasets.
> >
> > Now I use the following code that should me give me all child rows
> > belonging
> > to a parent.
> >
> >
> > test160106DataSetTableAdapters.ParentTableAdapter _pta = new
> > Test160106.test160106DataSetTableAdapters.ParentTableAdapter();
> >
> > foreach (test160106DataSet.ChildRow _childRow in
> > _pta.GetData().FindByID(1).GetChildRows())
> >
> > {
> >
> > Console.Write(String.Format("{0}: {1}", _childRow.ID, _childRow.Name));
> >
> > }
> >
> > Console.ReadLine();
> >
> > When executing this code, it gives me an Invalid Cast Exception (Unable to
> > cast object of type 'ParentRow[]' to type 'ChildRow[]'.), which comes from
> > the generated code:
> >
> > [System.Diagnostics.DebuggerNonUserCodeAttribute()]
> >
> > public ChildRow[] GetChildRows() {
> >
> > return
> > ((ChildRow[])(base.GetChildRows(this.Table.ChildRelations["FK_Child_Parent"])));
> >
> > }
> >
> >
> > Can anyone reproduce this? If so, is it a bug or am I doing someting I
> > shouldn't be?
> >
> > Any help appreciated.
> >
> > (originally posted this on C9
> > http://channel9.msdn.com/ShowPost.aspx?PostID=155801#155801, no help
> > there,
> > so I tried here)
>
>
>

Re: Typed Datasets - GetChildRows (Bug or am I doing something wro by Miha

Miha
Sun Feb 05 14:48:13 CST 2006

I suggest you to debug and check how is the relation in question set up (use
debugger).

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Gidion" <Gidion@discussions.microsoft.com> wrote in message
news:89B9A5D2-9796-4A45-AA51-24D82496447E@microsoft.com...
> Yes it is correct. (the first thing I checked.)
>
> In the example above and in the real example the relation was correct.
>
> "Miha Markic [MVP C#]" wrote:
>
>> Are you sure that relation in dataset is set correctly?
>> (dumb question)
>>
>> --
>> Miha Markic [MVP C#]
>> RightHand .NET consulting & development www.rthand.com
>> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
>>
>> "Gidion" <Gidion@discussions.microsoft.com> wrote in message
>> news:B79E5F75-1A92-4BF1-AEE7-952D1E353AF5@microsoft.com...
>> > Hi everybody!
>> >
>> > I've stumbled across a funny behaviour of a typed dataset in a new
>> > application of mine. Some how the generated code gives me a Invalid
>> > Cast
>> > Exception.
>> >
>> > I've reproduced the behaviour as follows.
>> > I've created a database "test160106", I've created the table "Parent"
>> > with
>> > two columns (column 1: ID int, column 2: nvarchar name) and a table
>> > "Child"
>> > with three columns (column 1: ID int, column 2: nvarchar name, column
>> > 3:
>> > int
>> > ParentID). I also added the relation between ParentID and Parent
>> > table.)
>> >
>> > I added a new data connection pointing to this database and let it
>> > create
>> > my
>> > datasets.
>> >
>> > Now I use the following code that should me give me all child rows
>> > belonging
>> > to a parent.
>> >
>> >
>> > test160106DataSetTableAdapters.ParentTableAdapter _pta = new
>> > Test160106.test160106DataSetTableAdapters.ParentTableAdapter();
>> >
>> > foreach (test160106DataSet.ChildRow _childRow in
>> > _pta.GetData().FindByID(1).GetChildRows())
>> >
>> > {
>> >
>> > Console.Write(String.Format("{0}: {1}", _childRow.ID, _childRow.Name));
>> >
>> > }
>> >
>> > Console.ReadLine();
>> >
>> > When executing this code, it gives me an Invalid Cast Exception (Unable
>> > to
>> > cast object of type 'ParentRow[]' to type 'ChildRow[]'.), which comes
>> > from
>> > the generated code:
>> >
>> > [System.Diagnostics.DebuggerNonUserCodeAttribute()]
>> >
>> > public ChildRow[] GetChildRows() {
>> >
>> > return
>> > ((ChildRow[])(base.GetChildRows(this.Table.ChildRelations["FK_Child_Parent"])));
>> >
>> > }
>> >
>> >
>> > Can anyone reproduce this? If so, is it a bug or am I doing someting I
>> > shouldn't be?
>> >
>> > Any help appreciated.
>> >
>> > (originally posted this on C9
>> > http://channel9.msdn.com/ShowPost.aspx?PostID=155801#155801, no help
>> > there,
>> > so I tried here)
>>
>>
>>