2009-02-25 56 views
1

有沒有辦法在配置時使用Castle Active Record爲表名添加前綴?使用Castle Active Record的表前綴使用Castle Active Record

[ActiveRecord("Address")] 
public class Address : ActiveRecord<Address> {} 

我想創建/引用的實際表格是「PRODAddress」或「DEBUGAddress」。有什麼內置的,我沒有看到?

謝謝

[編輯]我在下面標註的普遍的答案,但這裏是實現表前綴城堡活動記錄的實際代碼:

... 
ActiveRecordStarter.ModelsCreated += ActiveRecordStarter_ModelsCreated; 
ActiveRecordStarter.Initialize(source, typeof(Address)); 
... 

private static void ActiveRecordStarter_ModelsCreated(ActiveRecordModelCollection models, IConfigurationSource source) 
{ 
    string tablePrefix = ConfigurationManager.AppSettings["TABLE_PREFIX"]; 
    if (String.IsNullOrEmpty(tablePrefix)) return; 

    foreach (ActiveRecordModel model in models) 
    { 
     model.ActiveRecordAtt.Table = String.Format("{0}{1}", tablePrefix, model.ActiveRecordAtt.Table); 
    } 
} 
+0

加入ActiveRecord常見問題解答:http://using.castleproject.org/display/AR/FAQ – 2010-01-24 16:20:13

回答