tags:

views:

259

answers:

1

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?

+1  A: 

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.

Adam
You should contribute this as a patch on Github
John Sheehan
Done - http://github.com/adam7/SubSonic-3.0-Templates/commit/cf3a1979eb99b3e16c9e4459e66a5f4f25ef9e3e
Adam