Monday, April 26, 2004

CodeSmith template - DAL / Stored Proc wrapper

This really shouldn't be called a 'DAL', so I'm gonna start calling it my 'Stored Proc Wrapper' template instead.

Check it out.

This assumes the stored procedures are named as:
Inserttable
Updatetable
Gettable
Listtable
Deletetable

I created my stored procedures using the 'AllStoredProcedures' template that ships with CodeSmith.

It also assumes a class named 'Common' that contains a static ConnectionString attribute:

using System;
using Syste.Configuration;
public class Common {
public static string ConnectionString() {
get {return ConfigurationSettings.AppSettings["ConnectionString"];}
}
}


My app.config file looks like this:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ConnectionString" value="put your valid connection string here"/>
</appSetting>
</configuration>


Notice that I made all my 'Stored Procedure Wrapper' methods static. This way I can simply say:

DataSet ds = StoredProcedures.GetTable(ID);


<< Home

This page is powered by Blogger. Isn't yours?