Re: Persistent Data Objects architecture

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Erik Frey (eriksjunk_at_hotmail.com)
Date: 03/25/04


Date: Thu, 25 Mar 2004 16:52:56 -0700


    Mike,

    Comments in-line:

> I am struggling with what should I use for my business entities (typed
> datset, untyped datset, or custom class). In the past I have always used
> custom classes to represent my business entities. Now with ADO.Net it has
> opened my eyes to other solutions, namely datasets.

And oddly enough, anything I'd write here will be stale in a couple of
months. There's a lot of work being done to streamline the whole process of
designing and maintaining business objects. Microsoft has something coming
up called Whitehorse that sounds pretty interesting, but for now I would
wholly recommend a neat little app developed by Eric J. Smith over here:

http://www.ericjsmith.net/codesmith/

It's a template-based code generator that's pretty powerful. I use it for
custom collections (which will be unnecessary when generics come out), but
it also has some handy tools for creating custom business objects (custom
classes or typed datasets) straight from database schemas.

> I rather use untyped
> datasets however I do not want to create a untyped dataset based on user
> input from scratch. I guess I can retrieve the schema from the db but is
> this the best approach? I could create the schema at design time using
> typed datasets. I like the ease of use of a typed dataset when coding
> however I would have to redeploy my business entity assembly if the db
> structure changes. I guess the same is true if I use custom classes.

Well, using a DataAdapter.FillSchema on a blank dataset will dynamically
create the columns and column types from scratch, so that's a vote for
untyped datasets. However, if your database has multiple tables with
foreign keys you'd have to write some pretty fancy code to query your
database and build that into a dataset on the fly - that could get
complicated. Also, FillSchema doesn't handle AutoIncrement right (if I
remember correctly). So there are some issues.

The advantage you give for untyped datasets is that you don't have to
redeploy when your db structure changes. But if your underlying db
structure changes, this is probably going to mean updating your UI
assemblies, which means a redeploy anyway. So generally I prefer typed
datasets.

>More
> and more I look at datasets, I like the functionality (managing
concurrency,
> CRUD behaviors (updating)...) With datsets versus custom classes, I do
not
> have to reinvent the wheel when comes to db functionality. However with
> that said, in my application I need some extra functionality. For
example,
> my application is a calculation application thats needs to have user data
> (saved to db) and application data(user data converted for application use
> not saved to db as converted but rather user data) seperate.

Are these complicated calculations? The DataColumn in a DataTable (in a
DataSet) has a property called Expression that you can use to create
calculated columns. This might be a simpler solution.

> Right now I
> just have properties in my class for both data and pass the user data to
my
> data access layer to be saved and my business objects access the
application
> data (converted data) to be used. So, if I look my design, I really need
a
> hybrid solution. So, I am thinking of using the custom class and a
dataset
> (untyped). I can encapsulate the dataset and use properties to access the
> data from the dataset (if needed) and use the same approach for the
> application data I am using now. I have read the Microsoft article you
> suggested and it has helped me differentiate which solution is best. I
> guess there is a not clear cut choice and I see why most developers use
> custom classes because of performance, strong typing... I would love the
> best of both worlds and not have to deploy a new business entity assembly
> everytime my db structure changes (it will happen - not major changes only
> minor).

Take a look at CodeSmith. It may be right up your alley for writing your
own custom templates and generating your own hybrid typed datasets.

Erik



Relevant Pages