views:

531

answers:

2

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  A: 

I think you'll have to configure your own INamingStrategy

Sander Rijken

related questions