Table Prefix Using Castle Active Record

删除回忆录丶 提交于 2020-01-03 03:29:30

问题


Is there anyway to add a prefix to table names at configuration time using Castle Active Record?

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

I'd like the actual table created/referenced to be "PRODAddress" or "DEBUGAddress". Is there anything built-in like that I am not seeing?

Thank you,

[EDIT] I've marked the general answer below, but here is the actual code to implement table prefixes for 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);
    }
}

回答1:


You can use ActiveRecordStarter.RegisterExtension(IModelBuilderExtension extension) or the ActiveRecordStarter.ModelCreated event




回答2:


I think you'll have to configure your own INamingStrategy



来源:https://stackoverflow.com/questions/588360/table-prefix-using-castle-active-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!