473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data Access Layer Design

Hi guys,

Just came back to ASP.NET after a couple year hiatus and I have a
feeling that time has passed me by on some of this stuff re:
application design.

My biggest gripe as a programmer is how we handle the data access
layer- basically we have a class called DataAccess.cs with a bunch of
methods that return what we need to wherever is calling it. We're
using the data access app blocks, and here
is an example:

public string GetUserStatus( int UserID)
{
// Create the Database object, using the default database
service.
// The default database service is determined through
configuration.
Database db = DatabaseFactory.CreateDatabase();

// Set up the command: The stored procedure name
string sqlCommand = "usr_GetUserStatus";
DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);

// Add in the parameter values
dbCommandWrapper.AddInParameter("@StudentID", DbType.Int32,
StudentID);
dbCommandWrapper.AddOutParameter("@Status", DbType.String,
4);

db.ExecuteNonQuery(dbCommandWrapper);

// Return the statusID
string result = (string)
dbCommandWrapper.GetParameterValue("@Status");

return result;
}

Every one of these methods repeats most of these lines! It's ugly!
It's time consuming! It sucks. The sprocs are kinda verbose as well.
Having to set up a different method for each little thing we
create/read/update/delete and then having to
bubble that up through 4 different layers (db->sproc->data
layer->business logic or whatever) is really really time consuming as
well as ugly and difficult to manage (this app isn't doing a ton of
stuff but we still probably have 50 or 60 sprocs.)

What's the solution? This sucks, right? Is an O/R mapper the
solution? Something like nHibernate? Are all my problems gonna
magically be solved when we move to .NET 2.0? Please help, I just
don't know the right way to attack this.

Nov 20 '05 #1
5 2134

//
What's the solution? This sucks, right? Is an O/R mapper the
solution? Something like nHibernate? Are all my problems gonna
magically be solved when we move to .NET 2.0? Please help, I just
don't know the right way to attack this.
\\

I dont think ASP.NET 2.0 will make much difference when designing multi tier
systems. The fundementals of that requirement wont have changed with the new
revision.

I know what you mean about the wades of code one has to write, and its also
difficult sometimes to persaude yourself to not go directly to the DataLayer
when it seems to have no benefit to have to write something in the Business
Logic to redirect your request just because it 'Should' go through it.

I'm still pretty new to this so, in some ways Im a bit similar to your with
your long holiday, but Im sure perseverance will improve things.

In short though, there is no easy way to do this stuff if your going to do
it right ( or at least to the de Facto standard ) then you jsut have to put
in the work.

That in itself is difficult when you only want to create a few records and
find yourself coding and application that looks as if its going to be able
to perform remote brain surgery.

;-D


--
Best Regards

The Inimitable Mr Newbie º¿º
"JP Green" <do*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi guys,

Just came back to ASP.NET after a couple year hiatus and I have a
feeling that time has passed me by on some of this stuff re:
application design.

My biggest gripe as a programmer is how we handle the data access
layer- basically we have a class called DataAccess.cs with a bunch of
methods that return what we need to wherever is calling it. We're
using the data access app blocks, and here
is an example:

public string GetUserStatus( int UserID)
{
// Create the Database object, using the default database
service.
// The default database service is determined through
configuration.
Database db = DatabaseFactory.CreateDatabase();

// Set up the command: The stored procedure name
string sqlCommand = "usr_GetUserStatus";
DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);

// Add in the parameter values
dbCommandWrapper.AddInParameter("@StudentID", DbType.Int32,
StudentID);
dbCommandWrapper.AddOutParameter("@Status", DbType.String,
4);

db.ExecuteNonQuery(dbCommandWrapper);

// Return the statusID
string result = (string)
dbCommandWrapper.GetParameterValue("@Status");

return result;
}

Every one of these methods repeats most of these lines! It's ugly!
It's time consuming! It sucks. The sprocs are kinda verbose as well.
Having to set up a different method for each little thing we
create/read/update/delete and then having to
bubble that up through 4 different layers (db->sproc->data
layer->business logic or whatever) is really really time consuming as
well as ugly and difficult to manage (this app isn't doing a ton of
stuff but we still probably have 50 or 60 sprocs.)

What's the solution? This sucks, right? Is an O/R mapper the
solution? Something like nHibernate? Are all my problems gonna
magically be solved when we move to .NET 2.0? Please help, I just
don't know the right way to attack this.

Nov 20 '05 #2
Code generators, Code generators, Code generators. You got it!
Something like nHibernate or CodeSmith or Codus is the way to go. I
hate coding this repetative code as well. Using these tools is the way
around that.

Nov 20 '05 #3
"Every one of these methods repeats most of these lines! It's ugly!"
if you are using ms sql server then try using Microsoft Data Access
Application Block for .NET

http://msdn.microsoft.com/library/en...ml/daab-rm.asp
regards,

ersin gençtürk
"JP Green" <do*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi guys,

Just came back to ASP.NET after a couple year hiatus and I have a
feeling that time has passed me by on some of this stuff re:
application design.

My biggest gripe as a programmer is how we handle the data access
layer- basically we have a class called DataAccess.cs with a bunch of
methods that return what we need to wherever is calling it. We're
using the data access app blocks, and here
is an example:

public string GetUserStatus( int UserID)
{
// Create the Database object, using the default database
service.
// The default database service is determined through
configuration.
Database db = DatabaseFactory.CreateDatabase();

// Set up the command: The stored procedure name
string sqlCommand = "usr_GetUserStatus";
DBCommandWrapper dbCommandWrapper =
db.GetStoredProcCommandWrapper(sqlCommand);

// Add in the parameter values
dbCommandWrapper.AddInParameter("@StudentID", DbType.Int32,
StudentID);
dbCommandWrapper.AddOutParameter("@Status", DbType.String,
4);

db.ExecuteNonQuery(dbCommandWrapper);

// Return the statusID
string result = (string)
dbCommandWrapper.GetParameterValue("@Status");

return result;
}

Every one of these methods repeats most of these lines! It's ugly!
It's time consuming! It sucks. The sprocs are kinda verbose as well.
Having to set up a different method for each little thing we
create/read/update/delete and then having to
bubble that up through 4 different layers (db->sproc->data
layer->business logic or whatever) is really really time consuming as
well as ugly and difficult to manage (this app isn't doing a ton of
stuff but we still probably have 50 or 60 sprocs.)

What's the solution? This sucks, right? Is an O/R mapper the
solution? Something like nHibernate? Are all my problems gonna
magically be solved when we move to .NET 2.0? Please help, I just
don't know the right way to attack this.

Nov 20 '05 #4
He is using the DAAB from Microsoft which is found in their Enterprise
Library. But, using that cuts out some of the low level database access
code, however, writing the code to access this library can still be
repetitive.

Nov 20 '05 #5
Try this as an alternative. Spend a month creating your dream
GenericDataLayer that will accept calls like:

GenericDataLayer.MagicallyInsert("CustomerTable", 12, "sammy", true,
"notes...");

Now try debugging into it when it breaks!

The beautiful thing about using code generators to create all that
boilerplate wrapper code that you hate so much is that it is completely
readable and completely debugable. If you try to hand it a param of
the wrong type, it will break on the exact line that you need to deal
with.

Trust me. I once inherited a Giant Magic DataLayer that worked "most
of the time". After a week of sifting through ArrayLists of ArrayLists
of Objects trying to find the spot where it was miscasting my nullable
integer, I started quietly writing some CodeSmith templates that
produced output surprisingly similar to the code you posted.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hamed | last post by:
Hello I have employed as a developer in a software company that its team uses FoxPro / VB 6.0 / VC++ 6.0 as the developing tools and newly is going to migrate to VS.NET. There is a project...
0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
2
by: newbie | last post by:
Hello, If I have posted the question in the wrong group, I apologize. I am building a windows application (in c#) that will be interacting with an existing Access database. This database will...
2
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to...
18
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
5
by: Tina | last post by:
I'm reading about the "3-tier" design afforded by using Object Data Sources in the App_Data folder in 2.0 asp.net projects. To me, putting an object data source in a separate folder on the web...
6
by: Dhananjay | last post by:
hello everyone i have got a problem i want to design business layer, data access layer , presentation layer for asp.net using C#.net , can anyone help me to solve this problem. i want some...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.