subclassing a DataRow class in a typed dataset

T

Tim Mackey

hi,
i've started playing with the VS strongly typed datasets and i'm doing an experiment to see if they will be a viable replacement for my business objects.

the typed dataset contains a class for each of my row types, and i want to add 2 variables to this class (it's simulating files and folders, and i want to have a ChildFiles and ChildFolders arraylist added to each FolderRow, to give fast/easy hierarchical navigation)

i can do it by modifying the code directly, but that isn't so good for when the code gets re-generated by VS. so i created a class to derive from the FoldersRow class, but i can't promote any of the existing FolderRow objects (once they get filled by a dataAdapter) to my subclass type (listed below). i get 'Invalid cast' run time errors, even though it compiles ok.
public class FoldersRowHierarchy : StrongTypedDataSet.FoldersRow
{
public ArrayList childSections = new ArrayList();
public ArrayList childPages = new ArrayList();
internal FoldersRowHierarchy (DataRowBuilder rb) : base(rb) {}
}

i really appreciate any help anyone can give on this.
tim mackey.



\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3
 
F

Frans Bouma [C# MVP]

Tim said:
hi,
i've started playing with the VS strongly typed datasets and i'm doing an
experiment to see if they will be a viable replacement for my business
objects.

the typed dataset contains a class for each of my row types, and i want to
add 2 variables to this class (it's simulating files and folders, and i
want to have a ChildFiles and ChildFolders arraylist added to each
FolderRow, to give fast/easy hierarchical navigation)

i can do it by modifying the code directly, but that isn't so good for when
the code gets re-generated by VS. so i created a class to derive from the
FoldersRow class, but i can't promote any of the existing FolderRow objects
(once they get filled by a dataAdapter) to my subclass type (listed below).
i get 'Invalid cast' run time errors, even though it compiles ok. public
class FoldersRowHierarchy : StrongTypedDataSet.FoldersRow { public
ArrayList childSections = new ArrayList(); public ArrayList childPages =
new ArrayList(); internal FoldersRowHierarchy (DataRowBuilder rb) :
base(rb) {} }

A typed dataset really just defines properties for known columns. That's the
logic inside the class. Adding a property to that code gives problems: you
won't see the value of the memberfield exposed by the property in your
serialized data, because that is produced by the underlying datatable class
which just serializes columns.

If you want to add properties to a typed dataset, add columns and then
regenerate the typed dataset.

FB
 
T

Tim Mackey

hi frans,
many thanks for your reply.
i tried adding some columns in the data designer in VS, but the problem is
that the types i want to add are arraylists. no amount of tinkering with
the xml types: Any, Group, AnyGroup, etc. achieved any workable solutions,
they got turned into string datatypes in the typed dataset. have you any
ideas for how i could add such arraylist elements to the dataset?

thanks for any help.
tim


\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3
 
S

Steve Willcock

Tim,

one approach to use which allows subclassing of the generated code for a
DataSet is to use the AGDataSetGenerator that is part of the open source
ADO.NET powertoys project -
http://www.gotdotnet.com/Community/Workspaces/workspace.aspx?id=40d3e800-e2af-4220-a079-66552dd2b825

This tool generates classes for a dataset that can be inherited as necessary
allowing you to add to/ modify the standard DataSet functionality as
required. Check out Shaun Wildermuth's web site at http://www.adoguy.com/
for more details of this (Shaun is the guy behind the ADO.NET powertoys
project).

If you need a lot of control over the functionality of the generated classes
then this is a good way to go although it's not entirely straightforward -
see these areas of Shaun's site for further discussions

http://adoguy.com/content.aspx?id=book/datasetgenerator
http://adoguy.com/content.aspx?id=samplechapter/chapter1

--
Steve Willcock, MCSD
http://www.willcockconsulting.com/


hi,
i've started playing with the VS strongly typed datasets and i'm doing an
experiment to see if they will be a viable replacement for my business
objects.

the typed dataset contains a class for each of my row types, and i want to
add 2 variables to this class (it's simulating files and folders, and i want
to have a ChildFiles and ChildFolders arraylist added to each FolderRow, to
give fast/easy hierarchical navigation)

i can do it by modifying the code directly, but that isn't so good for when
the code gets re-generated by VS. so i created a class to derive from the
FoldersRow class, but i can't promote any of the existing FolderRow objects
(once they get filled by a dataAdapter) to my subclass type (listed below).
i get 'Invalid cast' run time errors, even though it compiles ok.
public class FoldersRowHierarchy : StrongTypedDataSet.FoldersRow
{
public ArrayList childSections = new ArrayList();
public ArrayList childPages = new ArrayList();
internal FoldersRowHierarchy (DataRowBuilder rb) : base(rb) {}
}
i really appreciate any help anyone can give on this.
tim mackey.


\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top