SubSonic 3 Simple Query Tool

好久不见. 提交于 2019-12-11 15:49:51

问题


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:


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.



来源:https://stackoverflow.com/questions/1110447/subsonic-3-simple-query-tool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!