views:

99

answers:

2

Hi,

on the configuration there's a way to set the tables we want to exclude but what I need is to set the name of the table I want to include, excluding everything else.

Have anyone already done this?

Cheers! Alex

+1  A: 

Ok, I've done it...

Just added the following line in a few places on the tt files: if(!ExcludeTables.Contains(tbl.Name)) {if((IncludeTables.Length != 0 && !IncludeTables.Contains(tbl.Name))) continue;

a slightly different line on the relations under the ActiveRecord.tt if(!ExcludeTables.Contains(fk.OtherTable)){ if((IncludeTables.Length != 0 && !IncludeTables.Contains(fk.OtherTable))) continue;

and added the following on the settings.ttinclude string[] IncludeTables = new string[]{ "tableA", "tableB" };

This is easy to implement but a future SubSonic update will erase my customization. Can this be added to the project?

Thanks! Alex

AlexCode
+1  A: 

There is another "Hack" whereby you only need to change Settings.ttinclude; just replace string[] ExcludeTables ... with:

public interface ITableExcluder
{
    bool Contains(string table);
    bool ShouldExclude(string table);
    bool ShouldInclude(string table);
}

/// <summary>
/// Custom class to exclude tables via a programmatic means.
/// </summary>
public class TableExcluder : ITableExcluder
{
    public bool Contains(string tableName)
    {
        if (ShouldExclude(tableName))
     return true;
        return !ShouldInclude(tableName);
    }

    public bool ShouldExclude(string tableName)
    {
        switch (tableName)
        {
            case "sysdiagrams":
     case "BuildVersion":
         return true;
        }

        if (tableName.StartsWith("blog_"))
            return true;

        return false;
    }

    public bool ShouldInclude(string tableName)
    {
        return true;
    }
}

//This replaces the string array    
ITableExcluder ExcludeTables = new TableExcluder();

A bit of a hack, but at least it avoids replacing parts of the other files!

Paul Mason
Looks nice! I'll try that!In fact my implementation demands changing code on all files which will be a problem on SubSonic updates.
AlexCode