首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubSonic 3 IncludeTables配置

SubSonic 3 IncludeTables配置
EN

Stack Overflow用户
提问于 2009-08-04 08:38:47
回答 2查看 169关注 0票数 1

在配置中,有一种方法可以设置要排除的表,但我需要的是设置要包括的表的名称,排除其他所有内容。

有没有人已经这么做了?

干杯!亚历克斯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-08-04 11:45:26

好了,我已经做到了..。

在tt文件的几个地方添加了下面这行: if(!ExcludeTables.Contains(tbl.Name)) {if((IncludeTables.Length != 0 &&!IncludeTables.Contains(tbl.Name);

如果(!ExcludeTables.Contains(fk.OtherTable)){ if((IncludeTables.Length != 0 &&!IncludeTables.Contains(fk.OtherTable)继续,则在ActiveRecord.tt下的关系上继续(!ExcludeTables.Contains(fk.OtherTable)){if((IncludeTables.Length!=0&&!IncludeTables.Contains(fk.OtherTable)

在settings.ttinclude string[] IncludeTables = string[]{ "tableA","tableB“}上添加了以下内容;

这很容易实现,但是将来的SubSonic更新将会删除我的自定义设置。可以将其添加到项目中吗?

谢谢!亚历克斯

票数 1
EN

Stack Overflow用户

发布于 2009-08-18 02:01:22

还有另一个“黑客”,你只需要更改Settings.ttinclude;只需替换string[] ExcludeTables……通过以下方式:

代码语言:javascript
复制
public interface ITableExcluder
{
    bool Contains(string table);
    bool ShouldExclude(string table);
    bool ShouldInclude(string table);
}

/// <summary>
/// Custom class to exclude tables via a programmatic means.
/// </summary>
public class TableExcluder : ITableExcluder
{
    public bool Contains(string tableName)
    {
        if (ShouldExclude(tableName))
        return true;
        return !ShouldInclude(tableName);
    }

    public bool ShouldExclude(string tableName)
    {
        switch (tableName)
        {
            case "sysdiagrams":
        case "BuildVersion":
            return true;
        }

        if (tableName.StartsWith("blog_"))
            return true;

        return false;
    }

    public bool ShouldInclude(string tableName)
    {
        return true;
    }
}

//This replaces the string array    
ITableExcluder ExcludeTables = new TableExcluder();

有点麻烦,但至少它避免了替换其他文件的一部分!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1226338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档