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); } }
You can use ActiveRecordStarter.RegisterExtension(IModelBuilderExtension extension) or the ActiveRecordStarter.ModelCreated event