Sql – Subsonic 3.0 and large SQL Database

sqlsubsonic3

Is there a way to limit the code generated to specific tables in a database? My database has a few hundred tables and I only really want to use SubSonic on a handfull of them.

Best Answer

You can modify the T4 templates to just limit the function call if the table name matches one of the tables you're interested in. Right now, it just checks for ExcludedTables. It looks like it would be pretty trivial to just add a whitelist as well. Try this.

In Settings.ttinclude, copy the

string[] ExcludeTables = new string[]{
"sysdiagrams",
"BuildVersion",
};

declaration, and paste a new array declaration called "IncludeTables". Add your table names to it. Then in Structs.tt, ActiveRecord.tt and Context.tt, do a search for "ExcludeTables". Wherever you find it, add in a check for your included tables. So change,

if(!ExcludeTables.Contains(tbl.Name))

to

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

That should get you started.