【问题标题】:SQL Views in SubSonic 3.0SubSonic 3.0 中的 SQL 视图
【发布时间】:2010-11-07 21:03:14
【问题描述】:

有什么方法可以在 SubSonic 3.0 中访问我的 SQL 视图?代码生成似乎完全跳过视图

【问题讨论】:

    标签: subsonic subsonic3


    【解决方案1】:

    在项目中包含视图

    只需打开 SQLServer.ttinclude 查找加载表的查询(搜索表单'const string TABLE_SQL') 然后改成

    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";
    

    如果你在 asp.net 项目中使用它,你可以像这样排除 aspnet 表和视图

    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_%'";
    

    【讨论】:

    • 唯一的问题是你在视图对象上有 Save()、Delete() 等方法,这些方法并不真正适用于视图
    • 我没有尝试保存或删除视图,但是 sql 明智的可以更新视图。我想最好的解决方案是为视图创建一个模板并返回只读对象。
    【解决方案2】:

    SubSonic 3 模板尚未生成视图代码。不过,您可以很容易地自己添加功能,请查看 SQLServer.ttinclude 中的 LoadTables 和 GetSPs 方法,了解 SubSonic 如何构建表\存储过程的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多