FreeSql.Repository (十一)分表


歡迎來到《FreeSql.Repository 倉儲模式》系列文檔,本系列文檔專注介紹 【倉儲+工作單元】 的使用方式。完整文檔請前往 wiki 中心:https://github.com/dotnetcore/FreeSql/wiki

FreeSql 支持分表、分庫方案,使用倉儲提供 AsTable 進行訪問更加方便。

var crud = fsql.GetSplitRepository<Log>(null, oldname => $"{oldname}_{DateTime.Now.ToString("YYYYMM")}");

上面我們得到一個日志倉儲對象按年月分表,使用它 CURD 最終會操作 Log_202012 表。

注意事項:

  • 使用 CodeFirst.SyncStructure 方法手工遷移分表;
  • 不可在分表分庫的實體類型中使用《延時加載》;
public static class YourExtensions
{
    public static IBaseRepository<TEntity> GetSplitRepository<TEntity>(this IFreeSql that, Func<string, string> asTable = null) where TEntity : class
    {
        var repo = new DefaultRepository<TEntity, int>(that, filter);
        repo.AsTable(asTable);
        return repo;
    }
}

系列文章導航


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM