歡迎來到《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;
}
}