表格前缀使用城堡活动记录

时间:2009-02-25 23:14:45

标签: castle-activerecord

是否有使用Castle Active Record在配置时为表名添加前缀?

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

我希望创建/引用的实际表是“PRODAddress”或“DEBUGAddress”。是否有任何内置的东西,我没有看到?

谢谢,

[编辑]我在下面标记了一般答案,但这里是实现Castle Active Record表格前缀的实际代码:

...
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);
    }
}

2 个答案:

答案 0 :(得分:1)

我认为您必须configure拥有自己的INamingStrategy

答案 1 :(得分:1)