Subsonic 3.0 uses T4 templates, which makes is very easy to extend.  One thing that is missing out of the box though, is the ability to specify only tables to be included.  The current download (version 3.0.0.3) has an array (ExcludeTables) for specifying table names that we don’t want to generate a DAL for, but if we want to generate only a few tables on a database that has 10s or even hundreds of tables, this is not very efficient.  It’s great that the T4 templates are very easy to extend.

Steps:

1. Create a new array to hold table names to be included.  Put this in Settings.ttinclude.

//this is a list of tables we explicitly want to include, if no records or null, then it is not used
//string[] IncludeTables = null;
string[] IncludeTables = new string []
{
    “Customers”
};

2. Look for any occurrence of ExcludeTables on the rest of the T4 files because we pretty much know the if statements dealing with this filters the list of tables to generate a DAL for.

Example
Change:
if(!ExcludeTables.Contains(tbl.Name))

to:

if(!ExcludeTables.Contains(tbl.Name) && ((IncludeTables == null || IncludeTables.Count() == 0) || IncludeTables.Contains(tbl.Name)))

That’s pretty much it.

Here is a zip file containing a working version.

SubSonic_3_0_0_3_MTY (zip file)