Updated Repository Layer (markdown)

AlexLEWIS
2021-09-08 10:38:03 +08:00
parent e10f8cf076
commit ca0deb63eb

@@ -130,27 +130,27 @@ var topicRepository = fsql.GetGuidRepository<Topic>(a => a.UserId == 1);
## Sharding Tables and Database
FreeSql 提供 AsTable 分表的基础方法GuidRepository 作为分存式仓储将实现了分表与分库(不支持跨服务器分库)的封装。
FreeSql provides a basic method of sharding tables through `AsTable`. As a distributed repository, and `GuidRepository` as a distributed storage, realizes the encapsulation of sharding tables and database (cross-server sharding-database is not supported).
```csharp
var logRepository = fsql.GetGuidRepository<Log>(null, oldname => $"{oldname}_{DateTime.Now.ToString("YYYYMM")}");
```
上面我们得到一个日志仓储按年月分表,使用它 CURD 最终会操作 Log_201903 表。
Above we got a log repository, which corresponds to the shareding-table by year and month. Using CURD operation will finally take effect in the `Log_201903` table.
注意事项:
Notice:
* v0.11.12以后的版本可以使用 CodeFirst 迁移分表;
* 不可在分表分库的实体类型中使用《延时加载》;
* Versions after v0.11.12 can use CodeFirst to migrate sharding tables.
* Do not use lazy loading in the entity type of sharding tables and database.
## Compatibility Problems
SqlServer 提供的 output inserted 特性,在表使用了自增或数据库定义了默认值的时候,使用它可以快速将 insert 的数据返回。PostgreSQL 也有相应的功能,如此方便但不是每个数据库都支持。
The `output inserted` feature provided by SqlServer. When the table uses auto-increment or the database defines a default value, use this feature to quickly return the inserted data. PostgreSQL also has similar functions, but not every database supports it.
当采用了不支持该特性的数据库(Sqlite/MySql/Oracle/达梦/MsAccess),并且实体使用了自增属性,仓储批量插入将变为逐条执行,可以考虑以下改进:
When a database that does not support this feature (Sqlite/MySql/Oracle/Damen/MsAccess) is used, and the entity uses auto-increment attributes, the batch insertion of the repository will be executed one by one. The following improvements can be considered:
* 使用 uuid 作为主键(即 Guid
* 避免使用数据库的默认值功能;
* Use uuid as the primary key (ie Guid).
* Avoid using the default value function of the database.
## Cascade Saving