2009-08-04 45 views
1

在配置上有一種方法來設置我們想要排除的表,但我需要的是設置我想包含的表的名稱,排除其他所有內容。SubSonic 3 IncludeTables配置

有沒有人已經這樣做?

乾杯! 亞歷

回答

1

好吧,我已經做到了......

只是添加以下行的TT文件的幾個地方: 如果 (ExcludeTables.Contains(tbl.Name)!) {if((IncludeTables.Length!= 0 & &!IncludeTables.Contains(tbl.Name)))continue;

上ActiveRecord.tt 下關係略微不同的行,如果(!ExcludeTables.Contains(fk.OtherTable)){ 如果((IncludeTables.Length!= 0 & &!IncludeTables.Contains(FK .OtherTable)))繼續;

加在settings.ttinclude以下 串[] IncludeTables =新的字符串[] { 「表A」, 「tableB的」};

這很容易實現,但未來的SubSonic更新將抹去我的定製。 這可以添加到項目中嗎?

謝謝! 亞歷克斯

1

還有另一個「黑客」,你只需要改變Settings.ttinclude;只需更換的String [] ExcludeTables ...有:

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(); 

一個黑客一點,但至少它避免了其他文件的更換零件!

+0

看起來不錯!我會嘗試的! 實際上,我的實現要求更改所有文件上的代碼,這些問題將成爲SubSonic更新的問題。 – AlexCode 2009-08-19 08:57:30