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:
<font size="2"> 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;
}</font>
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 what to do.