Business objects and class' w/ member DataSets

S

Steve

I'm designing my data access needs and have a couple of questions.
First of all, I can't get a straight answer what a "business object" is. I
typically create classes to represent my database tables, are those
"business objects"?

Is it more typical to pass the business objecs to the DAL methods or have
the business objects generate correct SQL and pass commands to the DAL?


I'm thinking of trying out a new type of business object where I encapsulate
a DataSet or DataTable in my object. Something like:
<code>
class BCustomer
{
private DataSet m_rawData;

public string CustomerName
{
get{ return m_rawData.Tables[0].Rows[0][0]; } // assuming
this is the index to the customer name?
set{ m_rawData.Tables[0].Rows[0][0] = value; } // ditto
}
}
</code>


This gives me strong typing and the flexibility of the DataSet/Table

Is this common? Anything I should know?

THANKS!
 
S

Steve

Steve said:
I'm designing my data access needs and have a couple of questions.
First of all, I can't get a straight answer what a "business object" is. I
typically create classes to represent my database tables, are those
"business objects"?

Is it more typical to pass the business objecs to the DAL methods or have
the business objects generate correct SQL and pass commands to the DAL?


I'm thinking of trying out a new type of business object where I encapsulate
a DataSet or DataTable in my object. Something like:
<code>
class BCustomer
{
private DataSet m_rawData;

public string CustomerName
{
get{ return m_rawData.Tables[0].Rows[0][0]; } // assuming
this is the index to the customer name?
set{ m_rawData.Tables[0].Rows[0][0] = value; } // ditto
}
}
</code>


This gives me strong typing and the flexibility of the DataSet/Table

Is this common? Anything I should know?

THANKS!


One more question, is it more typical to use the "Application Processing"
class to create a business object and assign the result of a DAL call or to
create the business object and call something like GetData() on the business
object and have it work with the DAL?
 
D

Darren Kopp

If you are looking to strongly type your applicaiton, you wouldn't use the
dataset or datatables. Check out this article to see why

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/CustEntCls.asp

Check out this article for the technical information about CollectionBase
class.
http://msdn.microsoft.com/library/d...systemcollectionscollectionbaseclasstopic.asp.

I don't know if there is a complete standard at how to approach DAL/Business
Object seperation, where one begins and the other ends. That will be a
choice that you will have to make.

-Darren Kopp
 
S

Steve

Darren Kopp said:
If you are looking to strongly type your applicaiton, you wouldn't use the
dataset or datatables. Check out this article to see why

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/CustEntCls.asp

Check out this article for the technical information about CollectionBase
class.
http://msdn.microsoft.com/library/d...systemcollectionscollectionbaseclasstopic.asp.

I don't know if there is a complete standard at how to approach DAL/Business
Object seperation, where one begins and the other ends. That will be a
choice that you will have to make.

-Darren Kopp

Thanks for the great response, Darren, I'm reading those articles right now.
I was happy to find the first article basically covering what I am already
implementing.

Have a good weekend!
Steve
 
S

Steve

Darren Kopp said:
If you are looking to strongly type your applicaiton, you wouldn't use the
dataset or datatables. Check out this article to see why

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/CustEntCls.asp

Check out this article for the technical information about CollectionBase
class.
http://msdn.microsoft.com/library/d...systemcollectionscollectionbaseclasstopic.asp.

I don't know if there is a complete standard at how to approach DAL/Business
Object seperation, where one begins and the other ends. That will be a
choice that you will have to make.

-Darren Kopp
<snip>

Darren,
One thing that I noticed from this article is that poppulated your nested
business object by calling member function on each class would open as many
connections to the database as your data is deep. In other words, for each
nested or related object, a connection would need to be opened and queries
executed. To me this seems like it could grow to quite a resource hog.

Currently I am getting a DataSet with all the relations setup, then
enumerating over the relations and created and nested the objects as needed.
This allows me to open and close the connection quite fast. The author's
approach is cleaner though, so I find myself with yet another decision to
make.

I thought of passing the connection object to the subsequent nested types
poppulation routines, but I think that if I had an open DataRead and passed
it's connection to another method that in turn created a different
DataReader it would invalidate the first one.

What are your thoughts on this?
 
D

Darren Kopp

Well, when I have done my stuff, I don't really need anything special
for connections, commands, etc, so I consider the classes contained in
System.Data.SqlClient my Data Layer. If a connection will only be
called by a certain thing (like BuildCarList), then I have it in it's
function. Also you can just have one connection and several commands.


If you need to execute commands that aren't both in the same class,
that reside in seperate functions, you could do something like pass the
connection by reference. I haven't done this myself yet, but I have
seen it done in some books that I have read. You will need to make
sure that you have full control over that connection object though
(i.e. you can't pass a connection by reference if you created that
connection in a using statement).

It's a bit weird to take the entity modeling approach at first, but I
have found it very helpful in keeping my code managable in large
projects.

Hope this helps,
Darren Kopp
http://blog.secudocs.com/
 

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