Home All Groups Group Topic Archive Search About

Design query - inherited data structures

Author
15 Feb 2006 11:11 PM
Toby Groves
Hi, after a bit of advice here if possible.

I have an application which needs to store several different types of
"document".  Each of these documents have many properties in common but
in addition will have some properties peculiar to themselves.  In normal
class parlance, I'd have a base document class which implements the core
functionality and from this I'd derived a class for each type of
document which extends the base class.

The question is how do I go about persisting these documents to a
database, particularly in the ADO.NET world.  Obviously each document
type will be stored in its own table which has columns to cater for all
the properties of that specific document type but I'm wondering what the
best way of organising the access to these tables is?

Can I implement any form of inheritance with typed DataSets in a similar
manner to classes, or do I have to implement a completely separate
DataSet for each document type, although much of the code would be
identical?  Even if I can use some form of inheritance, would there be
any mileage in doing so and what advantages or disadvantages would it
convey?

Would I possibly be better off using the aforementioned class hierarchy,
loading the data from the database into instances of these classes and
then binding interface components to these objects or is this needlessly
complex?  I'm a bit confused as to when to use business objects for
interface binding rather than DataSets but that's almost another
question.

If anyone can offer any advice in this area or better still, point me at
some reading material I can wade through I'd be most grateful.
--
Toby

Author
16 Feb 2006 1:52 AM
Sahil Malik [MVP C#]
Okay this is an interesting problem.

Assuming you can do SQl2k5, I'd recommend creating a table structure like
this ---

Table #1 ----

ObjectID
ObjectType
CommonProperty1
CommonProperty2
....
CommonPropertyn

Table #2 ----
(PK)
ObjectID (FK)
GenericProperty(XML) <-- tie it down with a schema
--

If Table #1 gets too wide, you may want to split it into two tables with a
one to one FK relationship.

Regards .NET code, I'd recommend not using datasets for this. I'd recommend
creating a base class business object with the common properties and
deriving specific objects and adding further properties and hydrating them
using SqlCommand.ExecuteReader or sump'n like dat :) (You could even use
Dataset to hydrate, it doesn't really matter).

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
__________________________________________________________


Show quote
"Toby Groves" <n***@iconia.org.uk> wrote in message
news:yem$uLAlU78DFwgK@iconia.org.uk...
> Hi, after a bit of advice here if possible.
>
> I have an application which needs to store several different types of
> "document".  Each of these documents have many properties in common but in
> addition will have some properties peculiar to themselves.  In normal
> class parlance, I'd have a base document class which implements the core
> functionality and from this I'd derived a class for each type of document
> which extends the base class.
>
> The question is how do I go about persisting these documents to a
> database, particularly in the ADO.NET world.  Obviously each document type
> will be stored in its own table which has columns to cater for all the
> properties of that specific document type but I'm wondering what the best
> way of organising the access to these tables is?
>
> Can I implement any form of inheritance with typed DataSets in a similar
> manner to classes, or do I have to implement a completely separate DataSet
> for each document type, although much of the code would be identical?
> Even if I can use some form of inheritance, would there be any mileage in
> doing so and what advantages or disadvantages would it convey?
>
> Would I possibly be better off using the aforementioned class hierarchy,
> loading the data from the database into instances of these classes and
> then binding interface components to these objects or is this needlessly
> complex?  I'm a bit confused as to when to use business objects for
> interface binding rather than DataSets but that's almost another question.
>
> If anyone can offer any advice in this area or better still, point me at
> some reading material I can wade through I'd be most grateful.
> --
> Toby

AddThis Social Bookmark Button