Building N-Tier applications with Visual Studio 2008

 

One of the most annoying features (for me) in using Visual Studio 2005 for building N-tier distributed applications has been the DataSet designer generated code. Visual Studio 2005 will generate code for your dataset, but will also put the table adapter code into the same file. This means that if you want to use the dataset in every layer of your application, you either have to deploy the database access logic on every layer (sickening!) or manually copy the data-access code to another file in your data access layer (annoying because every time you change the dataset you have to recopy the code).

Luckily this has been fixed in Visual Studio 2008, and now you can try this for yourself. First of all, the dataset designer generates the same code as VS2005 for backward compatibility, but you can turn this off. The idea is simple, simply create your dataset in your DAL project, and then tell the designer to generate the dataset's code in another project (the one containing the types you'll use in every layer, what I call the Framework layer). In the designer this looks like this (by clicking the background in the dataset designer and looking at the properties window):

image

This way you end up with the TableAdapters generated in the DAL layer, and the DataSet with DataTables, etc... in the Framework layer.

Now you can use the DataSet in every layer of your application by adding a reference to the framework layer, without adding a dependency on your table adapters:

image