【问题标题】:Table Prefix Using Castle Active Record使用 Castle Active Record 的表前缀
【发布时间】:2009-02-26 23:39:15
【问题描述】:

是否有在配置时使用 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);
    }
}

【问题讨论】:

标签: castle-activerecord


【解决方案1】:
【解决方案2】:

我认为你必须configure你自己的INamingStrategy

【讨论】:

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