SQL Views in SubSonic 3.0

坚强是说给别人听的谎言 提交于 2019-12-02 16:24:31

To include views in your project

simply open SQLServer.ttinclude Find the query that load the tables ( search form 'const string TABLE_SQL') then change it to

const string TABLE_SQL=@"SELECT *
    FROM  INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE' 
    union
    select Table_catalog, table_schema, table_name, 'View' table_type 
    from information_schema.views";

if you are using it in an asp.net project you can exclude the aspnet table and views like so

const string TABLE_SQL=@"SELECT *
    FROM  INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE' 
        and table_name not like '%aspnet_%'
    union
    select Table_catalog, table_schema, table_name, 'View' table_type 
    from information_schema.views
    where table_name not like '%aspnet_%'";

The SubSonic 3 templates don't generate code for views yet. You could add the functionality yourself quite easily though, have a look at the LoadTables and GetSPs methods in SQLServer.ttinclude to see how SubSonic builds lists of tables\stored procedures.

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