SubSonic 3 Simple Query Tool

subsonic

I want to use the Simple Query tool in SubSonic 3(.0.0.2) and the docs page (http://subsonicproject.com/docs/Simple_Query_Tool) implies there's a way to easily get hold of table column names (e.g. Product.ProductNameColumn):

int records = new Select(Product.ProductIDColumn, Product.ProductNameColumn).
                From<Product>().GetRecordCount();

The ActiveRecord generated class doesn't appear to expose this info – there is no ProductIDColumn property. Is this a hang-up from version 2?

Best Answer

There's no way to get the column names in SubSonic 3 at the moment. You can still use the simple query tool with strings or if you modify the Structs.tt template you can get them generated for you. Find this section of code (I think it's line 45):

<# foreach(var col in tbl.Columns){ #>
    public IColumn <#=col.CleanName#>{
      get{
        return this.GetColumn("<#=col.Name#>");
      }
    }            
<# }#> 

and modify it so it looks like this:

<# foreach(var col in tbl.Columns){ #>
    public IColumn <#=col.CleanName#>{
      get{
        return this.GetColumn("<#=col.Name#>");
      }
    }

    public static string <#= col.CleanName #>Column{
      get{
        return "<#= col.Name #>";
      }
    }

<# }#>   

Then you should get all your column names automatically generated as static properties.

Related Topic