mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-08 01:10:57 +08:00
update
21
分区分表.md
21
分区分表.md
@@ -48,14 +48,6 @@ var logRepository = fsql.GetGuidRepository<Log>(null, oldname => $"{oldname}_201
|
||||
|
||||
上面我们得到一个日志仓储按年月分表,使用它 CURD 最终会操作 Log_201903 表。
|
||||
|
||||
合并两个仓储,实现分表下的联表查询:
|
||||
|
||||
```csharp
|
||||
fsql.GetGuidRepository<User>().Select.FromRepository(logRepository)
|
||||
.LeftJoin<Log>(b => b.UserId == a.Id)
|
||||
.ToList();
|
||||
```
|
||||
|
||||
注意事项:
|
||||
|
||||
* 不能使用 CodeFirst 迁移分表,开发环境时仍然可以迁移 Log 表;
|
||||
@@ -83,14 +75,21 @@ select * from (SELECT a."Id" as1 FROM "table_3" a) ftb
|
||||
多表查询:
|
||||
```csharp
|
||||
var sql = fsql.Select<User>().LeftJoin<UserGroup>((a,b) => a.UserGroupId == b.Id)
|
||||
.AsTable((type, oldname) => "table_1")
|
||||
.AsTable((type, oldname) => "table_2")
|
||||
.AsTable((type, oldname) => "table_3")
|
||||
.AsTable((type, oldname) => oldname + "_1")
|
||||
.AsTable((type, oldname) => oldname + "_2")
|
||||
.AsTable((type, oldname) => oldname + "_3")
|
||||
.ToSql(a => a.Id);
|
||||
```
|
||||
|
||||
> 期待更多发散。。。
|
||||
|
||||
## 巧用AsTable
|
||||
```csharp
|
||||
var sql = fsql.Select<User>()
|
||||
.AsTable((a, b) => "(select * from tb_topic where clicks > 10)")
|
||||
.Page(1, 10).ToList()
|
||||
```
|
||||
|
||||
- [《租户》](https://github.com/2881099/FreeSql/wiki/%e7%a7%9f%e6%88%b7)
|
||||
- [《读写分离》](https://github.com/2881099/FreeSql/wiki/%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb)
|
||||
- [《性能》](https://github.com/2881099/FreeSql/wiki/%e6%80%a7%e8%83%bd)
|
||||
|
||||
7
单表查询.md
7
单表查询.md
@@ -34,6 +34,13 @@ sql = select.Where(a => new []{1,2,3}.Contains(a.Id)).ToSql();
|
||||
//WHERE (a.`Id` in (1,2,3))
|
||||
```
|
||||
|
||||
## 巧用AsTable
|
||||
```csharp
|
||||
var sql = fsql.Select<User>()
|
||||
.AsTable((a, b) => "(select * from user where clicks > 10)")
|
||||
.Page(1, 10).ToList()
|
||||
```
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [《多表查询》](https://github.com/2881099/FreeSql/wiki/%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2)
|
||||
|
||||
10
更新日志.md
10
更新日志.md
@@ -1,6 +1,16 @@
|
||||
|
||||
完整版本:年数-月-日-当日版本号,FreeSql、FreeSql.Repository、FreeSql.DbContext 版本号相同。
|
||||
|
||||
## v0.9.10
|
||||
|
||||
- 移除 FreeSql.Repository 扩展方法 FromRepository;
|
||||
- 调整 ISelect.AsTable 规则,每一次使用将增加 UNION ALL 查询;
|
||||
- 优化 AsTable UseSyncStructureToLower/ToUpper 设置,兼容 AsTable((t,o) => "(select * from tb)");
|
||||
|
||||
## v0.9.9
|
||||
|
||||
- 修复 AsTable 不受 UseSyncStructureToLower/ToUpper 设置的 bug;
|
||||
|
||||
## v0.9.8
|
||||
|
||||
- 增加 AsTable 多次,可查询分表后的多个子表记录,以 UNION ALL 形式执行;
|
||||
|
||||
7
租户.md
7
租户.md
@@ -42,12 +42,9 @@ var reposTopic = orm.GetGuidRepository<Topic>(null, oldname => $"{oldname}{tenan
|
||||
|
||||
```csharp
|
||||
var tenantId = 1;
|
||||
var reposTopic = orm.GetGuidRepository<Topic>(null, oldname => $"{oldname}{tenantId}");
|
||||
var reposType = orm.GetGuidRepository<TopicType>(null, oldname => $"{oldname}{tenantId}");
|
||||
|
||||
//联表查询也支持
|
||||
reposTopic.Select
|
||||
.FromRepository(reposType) //合并两个仓储的设置
|
||||
fsql.Select<Topic>()
|
||||
.AsTable((type, oldname) => $"{oldname}{tenantId}")
|
||||
.LeftJoin<TopicType>((a, b) => a.TypeId == b.Id)
|
||||
.ToList();
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user