typed datasets vs. business objects

B

BillE

I'm trying to decide if it is better to use typed datasets or business
objects, so I would appreciate any thoughts from someone with more
experience.

When I use a business object to populate a gridview, for example, I loop
through a datareader, populating an array list with instances of a custom
class in the middle tier, and then send the array list up to the
presentation layer and bind the gridview to it.

If I use a typed dataset, I just fill it with a data adapter and then bind
it to the gridview.

It seems like the typed dataset would be more efficient, because I don't
have to loop through anything. But typed datasets are aggravating, because
it seems like they have to be defined all the way down at the data access
layer to be accessible in a n-tier solution. They clutter up my solution.

Business objects seem tidier, and seem more professional, but are they as
efficient, with all the looping required?

Thanks
Bill
 
M

Mr. Arnold

BillE said:
I'm trying to decide if it is better to use typed datasets or business
objects, so I would appreciate any thoughts from someone with more
experience.

When I use a business object to populate a gridview, for example, I loop
through a datareader, populating an array list with instances of a custom
class in the middle tier, and then send the array list up to the
presentation layer and bind the gridview to it.

If I use a typed dataset, I just fill it with a data adapter and then bind
it to the gridview.

It seems like the typed dataset would be more efficient, because I don't
have to loop through anything. But typed datasets are aggravating,
because it seems like they have to be defined all the way down at the data
access layer to be accessible in a n-tier solution. They clutter up my
solution.

Business objects seem tidier, and seem more professional, but are they as
efficient, with all the looping required?

So why can't you just use a Business Object that accesses a DAL object that
brings back the dataset and bind it to the grid's data source? There is
nothing stopping you from doing that. The UI or Presentation tier should not
directly access a database.

There is nothing stopping you from making a DAL object that access a
database table , populate a dataset and return that dataset all the way back
to the UI through the Business Layer and bind the dataset to the control.

As a matter of fact, the UI should totally be unaware of the Business
objects (loosely coupled) UI with the Business Object layer, which is
accomplished with the Presentation layer interfaces that interact with the
Business layer objects. You can send down or bring up things like datasets,
arraylist, strings, List, int. long or whatever through the interface of the
Presentation tier.

What am I talking about?

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

But for the example you're presently concerned about, just bring back the
dataset from the DAL to the BUS and bind the dataset to the control.

Busobject bo = new Busobject();

datagrid1,Datasource = bo.GetDataset(); // the DAL returns a dataset to
the BUS and the BUS returns a dataset binds the dataset to the control.
 
J

John Sheppard

BillE said:
I'm trying to decide if it is better to use typed datasets or business
objects, so I would appreciate any thoughts from someone with more
experience.

When I use a business object to populate a gridview, for example, I loop
through a datareader, populating an array list with instances of a custom
class in the middle tier, and then send the array list up to the
presentation layer and bind the gridview to it.

If I use a typed dataset, I just fill it with a data adapter and then bind
it to the gridview.

It seems like the typed dataset would be more efficient, because I don't
have to loop through anything. But typed datasets are aggravating,
because it seems like they have to be defined all the way down at the data
access layer to be accessible in a n-tier solution. They clutter up my
solution.

Business objects seem tidier, and seem more professional, but are they as
efficient, with all the looping required?

Thanks
Bill

Im sure behind the scenes datasets loop through things anyway....besides
thats what computers do, they loop...I wouldnt worry to much about that...

I'm by no means a guru. As I have only really experienced datasets, but I
have done lots and lots and lots of reading on them vs custom objects. All
my research can pretty much be sumed up with the following ; Datasets are
excellent for small projects but large and/or complicated projects they just
keep you hemmed in....so for big project it's worth the setup of custom
objects.

My current project is based on datasets and its groovy in some regards, but
its going to become a real pain in the butt later down the track.

The amount of work I have done to just get my datasets generated has been
too much....Draggin and dropping stuff on to xsd every time the DB
changes....ugg...so im trying to generate them and its no easy task.....I
wish we had of gone custom business objects...but then I havent been there
so I cant tell you....but thats where everything points...

I like neat also....it means quicker more readable code...its worth
alot...datasets are by no means neat :(

Hope that helps
John Sheppard
 
M

Mr. Arnold

John Sheppard said:
Im sure behind the scenes datasets loop through things anyway....besides
thats what computers do, they loop...I wouldnt worry to much about that...

I'm by no means a guru. As I have only really experienced datasets, but I
have done lots and lots and lots of reading on them vs custom objects. All
my research can pretty much be sumed up with the following ; Datasets are
excellent for small projects but large and/or complicated projects they
just keep you hemmed in....so for big project it's worth the setup of
custom objects.

My current project is based on datasets and its groovy in some regards,
but its going to become a real pain in the butt later down the track.

The amount of work I have done to just get my datasets generated has been
too much....Draggin and dropping stuff on to xsd every time the DB
changes....ugg...so im trying to generate them and its no easy task.....I
wish we had of gone custom business objects...but then I havent been there
so I cant tell you....but thats where everything points...

I like neat also....it means quicker more readable code...its worth
alot...datasets are by no means neat :(

Why does this person need a custom business object in an Arraylist of
objects in the case of binding data to a control? If the dataset is being
used in a forward only manner, then simply binding the dataset to the
control is a much cleaner and faster solution.

And I beg to differ with you about a dataset being used in big projects. I
worked at a client site that used an in-house written object code generator
that pointed to SQL based on using stored procedures only, and everything
was generated using datatables and datasets in the DAL. The DAL was used by
Windows Desktop, Windows Service and Web applications, which was also used
in large projects.

A dataset is just a representation of data in memory. That's all it is, and
datasets used in a DAL is just as fast and a viable solution than using
custom objects at the DAL that are not using datasets and datatables, which
one could still customize the code of the DAL that used the DAL database
engine.

It's a mistake using datasets and datatables in the UI in your example
above. The database access should have been extracted from the UI so that
one doesn't face the problems that you are facing or will face for large
projects.
 
C

Cor Ligthert[MVP]

Bill,

What is your goal to make a sollution or to make something that has the
elitair sound of profesionality.

As soon as you do something that is elitair right, then you are probably
doing something wrong, otherwise it was accepted as well by others then the
bookwritting so called professionals..

(By this I do not mean all bookwritters).

Just my opinion.

Cor
 
S

sloan

Outside of Reporting, I use custom business objects 99.9% of the time.

Here is an example:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!139.entry

Find the MS article I mention here ("bird's eye view") and read that thing
about 4 times.

...

SOMEBODY has to pay the looping price. Just because in a DataSet you're
encapsulated from it, the DataSet is being internally populated (via
looping) with an IDataReader.

Get the download code from the URL above. Somewhere I have a test that
shows the difference between a CustomCollection being populated, and a
DataSet (with constaints ON) and a DataSet (with constraints turned OFF).

I think the results will surprise you.

...

I wouldn't go back to a purely dataset model for ... an extra $30K salary.
They're such a pain in the butt, esp with Generics.
And finding data in a DataSet.Table with the el-crappo .Select method sucks.


PS

In 2.0, you'd be better off (IMHO, I know others may disagree) defined
something like:

public EmployeeCollection : List<Employee>
{
//that's it, that's all the code
}

instead of a return ArrayList.




At my blog above, I have a 2.0 version of that article.
Also check out my WCF/Interfaces blog entry, and just ignore the WCF stuff.
I have interfaces and custom objects/collections defined there.

IZebra
IZebraCollection
Zebra
ZebraCollection


...
 
J

John Sheppard

Mr. Arnold said:
Why does this person need a custom business object in an Arraylist of
objects in the case of binding data to a control? If the dataset is being
used in a forward only manner, then simply binding the dataset to the
control is a much cleaner and faster solution.

And I beg to differ with you about a dataset being used in big projects. I
worked at a client site that used an in-house written object code
generator that pointed to SQL based on using stored procedures only, and
everything was generated using datatables and datasets in the DAL. The
DAL was used by Windows Desktop, Windows Service and Web applications,
which was also used in large projects.

Thats exactly what we are doing...its taken me many weeks develop that
inhouse dal. I think it woulda been much quicker to use an orm of some kind
that generates the custom objects.

I am out of my league here tho, I should not have spoken so confidently :S
A dataset is just a representation of data in memory. That's all it is,
and datasets used in a DAL is just as fast and a viable solution than
using custom objects at the DAL that are not using datasets and
datatables, which one could still customize the code of the DAL that used
the DAL database engine.

Yeah, I guess I meant to say that just because he isnt writing the looping
code doesnt mean there isnt any there.
It's a mistake using datasets and datatables in the UI in your example
above. The database access should have been extracted from the UI so that
one doesn't face the problems that you are facing or will face for large
projects.

What would you bind to if there was no datasets to use at the UI level?

At current we just have one massive dataset which I use bindingsources to
attach to on the UI...

Thank you
John
 
M

Mr. Arnold

John Sheppard said:
Thats exactly what we are doing...its taken me many weeks develop that
inhouse dal. I think it woulda been much quicker to use an orm of some
kind that generates the custom objects.

It took me all of 10 minutes to complete any code in the DAL using datasets
and datatables. The in-house written code generator created the DAL objects
that the in-house written database engine used. What I mean is someone wrote
the code to access SQL Server tables to create the primitive field types,
etc, etc. Someone wrote the (DLL) code for the database engine that was
inplemented in each DAL object. In other words, it was short of an ORM
application that was in-house written and worked well.
I am out of my league here tho, I should not have spoken so confidently :S


Yeah, I guess I meant to say that just because he isnt writing the looping
code doesnt mean there isnt any there.


What would you bind to if there was no datasets to use at the UI level?

The mistake is if you are making direct calls from the UI to the database.
If you are going through UI-BL-DAL, that's not a problem. Direct database
access should be extracted from the UI.
At current we just have one massive dataset which I use bindingsources to
attach to on the UI...

Really? That's kind of ugly. But it's all in one dataset in memory. What
happens when you have to update or insert records into a database?
 
J

John Sheppard

Mr. Arnold said:
It took me all of 10 minutes to complete any code in the DAL using
datasets and datatables. The in-house written code generator created the
DAL objects that the in-house written database engine used. What I mean is
someone wrote the code to access SQL Server tables to create the primitive
field types, etc, etc. Someone wrote the (DLL) code for the database
engine that was inplemented in each DAL object. In other words, it was
short of an ORM application that was in-house written and worked well.


The mistake is if you are making direct calls from the UI to the database.
If you are going through UI-BL-DAL, that's not a problem. Direct database
access should be extracted from the UI.

ahh ic...yeah nah thats how we are doing it...UI-BL-DAL..
Really? That's kind of ugly. But it's all in one dataset in memory. What
happens when you have to update or insert records into a database?

Its ugly :) Very ugly...somewhere along the line I'd imagine I will be
forced to break it up, but for now it works well enough.

To persist it to the database I just loop through the dataset using
getchanges and execute an autogenerated sql statement for each one thats had
a change. It's not exactly efficient but it's working so far although I
*suspect* I will start having problems somewhere down the line...

It's on a webservice which complicated things, but getting all that stuff
working took me mroe time than I would have liked and I just figured I would
have been better off just paying for an ORM.

I guess put it this way; I don't feel 100% confident that im not going to
run into problems with my dataset architecture. I feel more confident with
an orm and custom objects because thats what seems to be what most blogs
live and die by, so I figure there must be a reason :)

Regards
John
 
C

Cor Ligthert[MVP]

Hi,

Mr. Arnold,

In my idea you give some generalized own opinions, which can be true,
however not forever.

If you use an application that uses a database, that has one table and one
UI, then we are in my idea in another situation then where we have a
database with thousand tables and thousand of UI's.

In the first situation code seperated in layers give awful readable code.

In my idea we should never generalise.

Cor
 
M

Mr. Arnold

Cor Ligthert said:
Hi,

Mr. Arnold,

In my idea you give some generalized own opinions, which can be true,
however not forever.

If you use an application that uses a database, that has one table and one
UI, then we are in my idea in another situation then where we have a
database with thousand tables and thousand of UI's.

Of course if one little program with one little database table is in use,
then of course on your thinking, it is applicable. One has to use common
sense.
In the first situation code seperated in layers give awful readable code.

The generalization is about N-tier architecture in projects that have the
logical tier and physical tier separation of UI/BL/DAL, which was talked
about by the posters in this thread, not some single form with one database
solution with no tier separation logical or physical.

I will always talk about the separation/extraction of the database logic
from the UI. I will always emphasize that the loosely coupled relationship
between the UI and the BL should be applied. The UI should be unaware of the
BL in an N-tier solution, which makes for better testing and scalability of
the N-tier solution with the use of interfaces to the BL through a
presentation tier.

Those are viable enterprise solutions I am talking about that most .Net
developers really don't have a clue about it. I will also emphasize that if
you're using datasets and datatables with direct connections to the database
in the UI in a large project or a project the needs to be scalable, then
one had better think about what he or she is doing and re-factor that
solution, because all you're facing is a nightmare. I have been there and
seen it too many times shaking my head with others saying that this is a
piece of junk, and a maintenance nightmare for anyone that follows.
 
C

Cor Ligthert[MVP]

Mr Arnold,

We have no discussion about what you wrote, however sometimes I have the
idea that persons want to make one form, with one textbox, with one table,
with one column and then start to spread it in 1000 lines of code because of
what they have read that it should be done.

:)

Cor
 

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