代码之家  ›  专栏  ›  技术社区  ›  ConsultUtah

使用Castle活动记录的表前缀

  •  1
  • ConsultUtah  · 技术社区  · 17 年前

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

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

    非常感谢。

    [编辑]我在下面标记了一般答案,但下面是为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 回复  |  直到 17 年前
        2
  •  1
  •   Sander Rijken    17 年前
    推荐文章