Groups | Blog | Home
all groups > dotnet ado.net > august 2007 >

dotnet ado.net : Strongly Typed Dataset should be in DataAccess Layer or Business Layer


kittipong.kiatcheeranun NO[at]SPAM gmail.com
8/28/2007 6:06:16 PM
I am not exactly sure that my understanding is right or wrong. In
strongly typed dataset we can generate all of the fields from tables
in database and also has tableadapter that allow us to write down sql
command in or directly link to table. We still can write the code in
dataset partial class for validating data as well.
As far as I understand strongly typed dataset is in both of Business
layer and data access layer, isn't it? Because validation rules code
and all datatable's fields should be in business layer and
tableadapter which is tied to sql command and connection string should
be in data access layer. Is this right or wrong? Any suggestion or
does it have any best way if I want to use strongly typed dataset in
my project.
Cor Ligthert[MVP]
8/29/2007 12:00:00 AM
Kittipong,

It depends on the project, however I do it for larger project as you told.
However it is even possible to set your simple checkings in the field
descriptors in the SQL server, that is then exposed in the strongly typed
dataset which makes then an easy early check even automatically in the UI
possible, as it is about binded controls.

The cavatat of that is that it needs forever maintenance at the SQL server
side. I agree with you that this all does not make everything clear.

Cor

<kittipong.kiatcheeranun@gmail.com> schreef in bericht
news:1188349576.118470.74270@x35g2000prf.googlegroups.com...
[quoted text, click to view]
kittipong.kiatcheeranun NO[at]SPAM gmail.com
8/29/2007 12:46:35 AM
On Aug 29, 1:30 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
[quoted text, click to view]

Thanks for the answer Cor. I still have a thing that confusing me. For
DataAccess Layer should it know about StronglyTyped dataset? For
example, I have a insert product method in my Data Access Layer as the
first method below:

1. First Method:
public static int Insert(string productName, int categoryID, decimal
unitPrice)
{
Database myDatabase = DatabaseFactory.CreateDatabase();
DBCommandWrapper myCommand =
myDatabase.GetStoredProcCommandWrapper("entlibProductsInsert");

myCommand.AddInParameter("@ProductName", DbType.String,
productName);
myCommand.AddInParameter("@CategoryID", DbType.Int32, categoryID);
myCommand.AddInParameter("@UnitPrice", DbType.Currency, unitPrice);

// Execute the query and return the new identity value
return Convert.ToInt32(myDatabase.ExecuteScalar(myCommand));
}

2. Second Method:
public static int Insert(ProductDataSet productDataSet)
{
Database myDatabase = DatabaseFactory.CreateDatabase();
DBCommandWrapper myCommand =
myDatabase.GetStoredProcCommandWrapper("entlibProductsInsert");

myCommand.AddInParameter("@ProductName", DbType.String,
productName);
myCommand.AddInParameter("@CategoryID", DbType.Int32, categoryID);
myCommand.AddInParameter("@UnitPrice", DbType.Currency, unitPrice);

// Execute the query and return the new identity value
return Convert.ToInt32(myDatabase.ExecuteScalar(myCommand));
}

In my case If I want to change parameter to be strongly typed dataset
as shown in my second method, do I need to move my strongly typed
dataset to DataAccess Layer or it should be separated in another
layer? What I am thinking I may put my strongly typed dataset in
another layer called Business Entity because the strongly typed needs
to share with DataAccess, Business and UI (binding control) as well.

I am not sure it's right or wrong and I don't really know how other
people do it, any suggestion will be really appreciated.

Regards,
Kittipong

kittipong.kiatcheeranun NO[at]SPAM gmail.com
8/29/2007 6:25:12 PM
On Aug 30, 3:23 am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
[quoted text, click to view]

Thank for your answer cor. It helped me out a lot :). And I also skim
read through Patterns of Enterprise Applicaiton Architecture (Martin
Fowler) and MS Designing Data Tier Components and Passing Data Through
Tiers. These two books are great and answer a heap of my questions as
well.

Regards,
Kittipong
Cor Ligthert[MVP]
8/29/2007 7:23:27 PM
kittipong,

Be aware that you never move an object between layers, you only give the
reference by value, therefore I like it very much to give the object that it
is about. In your case the strongly typed dataset.

Cor

<kittipong.kiatcheeranun@gmail.com> schreef in bericht
news:1188373595.643692.58390@x35g2000prf.googlegroups.com...
[quoted text, click to view]
AddThis Social Bookmark Button