mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
update
This commit is contained in:
parent
429fc99d1b
commit
357494a28f
@ -13,8 +13,10 @@
|
|||||||
### 测试代码
|
### 测试代码
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var mysql = new MySql("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=3");
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
IDelete<Topic> delete => mysql.Delete<Topic>();
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
|
.Build();
|
||||||
|
IDelete<Topic> delete => fsql.Delete<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -40,16 +42,16 @@ dywhere 支持
|
|||||||
* new { id = 1 }
|
* new { id = 1 }
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var t1 = mysql.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
var t1 = fsql.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||||
//DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)
|
//DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)
|
||||||
|
|
||||||
var t2 = mysql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
var t2 = fsql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
|
||||||
//DELETE FROM `tb_topic` WHERE (`Id` = 1)
|
//DELETE FROM `tb_topic` WHERE (`Id` = 1)
|
||||||
|
|
||||||
var t3 = mysql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
var t3 = fsql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
|
||||||
//DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)
|
//DELETE FROM `tb_topic` WHERE (`Id` = 1 OR `Id` = 2)
|
||||||
|
|
||||||
var t4 = mysql.Delete<Topic>(new { id = 1 }).ToSql();
|
var t4 = fsql.Delete<Topic>(new { id = 1 }).ToSql();
|
||||||
//DELETE FROM `tb_topic` WHERE (`Id` = 1)
|
//DELETE FROM `tb_topic` WHERE (`Id` = 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
### 测试代码
|
### 测试代码
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var mysql = new MySql("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=3");
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
IInsert<Topic> insert => mysql.Insert<Topic>();
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
|
.Build();
|
||||||
|
IInsert<Topic> insert => fsql.Insert<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
||||||
|
155
Docs/select.md
155
Docs/select.md
@ -46,3 +46,158 @@
|
|||||||
| As | \<this\> | string alias = "a" | 指定别名 |
|
| As | \<this\> | string alias = "a" | 指定别名 |
|
||||||
| Master | \<this\> | | 指定从主库查询(默认查询从库) |
|
| Master | \<this\> | | 指定从主库查询(默认查询从库) |
|
||||||
| Caching | \<this\> | int seconds, string key = null | 缓存查询结果 |
|
| Caching | \<this\> | int seconds, string key = null | 缓存查询结果 |
|
||||||
|
|
||||||
|
## 测试代码
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
|
.Build();
|
||||||
|
ISelect<Topic> select => fsql.Select<Topic>();
|
||||||
|
|
||||||
|
[Table(Name = "tb_topic")]
|
||||||
|
class Topic {
|
||||||
|
[Column(IsIdentity = true, IsPrimary = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int Clicks { get; set; }
|
||||||
|
public int TestTypeInfoGuid { get; set; }
|
||||||
|
public TestTypeInfo Type { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
class TestTypeInfo {
|
||||||
|
public int Guid { get; set; }
|
||||||
|
public int ParentId { get; set; }
|
||||||
|
public TestTypeParentInfo Parent { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
class TestTypeParentInfo {
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# Where
|
||||||
|
|
||||||
|
### 单表
|
||||||
|
```csharp
|
||||||
|
var sql = select.Where(a => a.Id == 10).ToSql();
|
||||||
|
///SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.`Id` = 10)
|
||||||
|
|
||||||
|
sql = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100).ToSql();
|
||||||
|
///SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.`Id` = 10 AND a.`Id` > 10 OR a.`Clicks` > 100)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 多表,使用导航属性
|
||||||
|
```csharp
|
||||||
|
sql = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TestTypeInfoGuid).ToSql();
|
||||||
|
///SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a, `TestTypeInfo` a__Type WHERE (a__Type.`Name` = 'typeTitle' AND a__Type.`Guid` = a.`TestTypeInfoGuid`)
|
||||||
|
|
||||||
|
sql = select.Where(a => a.Type.Parent.Name == "tparent").ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a, `TestTypeInfo` a__Type, `TestTypeParentInfo` a__Type__Parent WHERE (a__Type__Parent.`Name` = 'tparent')
|
||||||
|
```
|
||||||
|
|
||||||
|
### 多表,没有导航属性
|
||||||
|
```csharp
|
||||||
|
sql = select.Where<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "typeTitle").ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a, `TestTypeInfo` b WHERE (b.`Guid` = a.`TestTypeInfoGuid` AND b.`Name` = 'typeTitle')
|
||||||
|
|
||||||
|
sql = select.Where<TestTypeInfo, TestTypeParentInfo>((a, b, c) => c.Name == "tparent").ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a, `TestTypeParentInfo` c WHERE (c.`Name` = 'tparent')
|
||||||
|
```
|
||||||
|
|
||||||
|
### 多表,任意查
|
||||||
|
```csharp
|
||||||
|
sql = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||||
|
.Where(a => a.Id == 10 && c.Name == "xxx")
|
||||||
|
.Where(a => b.ParentId == 20)).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a, `TestTypeParentInfo` c, `TestTypeInfo` b WHERE (a.`Id` = 10 AND c.`Name` = 'xxx') AND (b.`ParentId` = 20)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 原生SQL
|
||||||
|
```csharp
|
||||||
|
sql = select.Where("a.clicks > 100 && a.id = ?id", new { id = 10 }).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.clicks > 100 && a.id = ?id)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 以上条件查询,支持 WhereIf
|
||||||
|
|
||||||
|
# 联表
|
||||||
|
|
||||||
|
### 使用导航属性联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid`
|
||||||
|
|
||||||
|
sql = select
|
||||||
|
.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
|
||||||
|
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 没有导航属性联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON b.`Guid` = a.`TestTypeInfoGuid`
|
||||||
|
|
||||||
|
sql = select
|
||||||
|
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
|
||||||
|
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON b.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfo` c ON c.`Id` = b.`ParentId`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 联表任意查
|
||||||
|
```csharp
|
||||||
|
sql = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||||
|
.LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
|
||||||
|
.LeftJoin(a => b.ParentId == c.Id)).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON a.`TestTypeInfoGuid` = b.`Guid` LEFT JOIN `TestTypeParentInfo` c ON b.`ParentId` = c.`Id`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 原生SQL联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin("TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname", new { bname = "xxx" }).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a LEFT JOIN TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname
|
||||||
|
```
|
||||||
|
|
||||||
|
# 查询数据
|
||||||
|
|
||||||
|
### 返回 List
|
||||||
|
```csharp
|
||||||
|
List<Topic> t1 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 返回 List + 导航属性的数据
|
||||||
|
```csharp
|
||||||
|
List<Topic> t5 = select.LeftJoin<TestTypeInfo>((a, b) => a.TypeGuid == b.Guid && b.Name == "111").ToList();
|
||||||
|
//此时会返回普通字段 + 导航对象 Type 的数据
|
||||||
|
```
|
||||||
|
|
||||||
|
### 指定字段返回
|
||||||
|
```csharp
|
||||||
|
//返回一个字段
|
||||||
|
List<int> t2 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => a.Id);
|
||||||
|
|
||||||
|
//返回匿名类
|
||||||
|
List<匿名类> t3 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => new { a.Id, a.Title });
|
||||||
|
|
||||||
|
//返回元组
|
||||||
|
List<(int, string)> t4 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList<(int, string)>("id, title");
|
||||||
|
```
|
||||||
|
|
||||||
|
### 执行SQL返回数据
|
||||||
|
```csharp
|
||||||
|
class xxx {
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string Title2 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
List<xxx> t3 = fsql.Ado.Query<xxx>("select * from song");
|
||||||
|
List<(int, string ,string)> t4 = fsql.Ado.Query<(int, string, string)>("select * from song");
|
||||||
|
List<dynamic> t5 = fsql.Ado.Query<dynamic>("select * from song");
|
||||||
|
```
|
||||||
|
|
||||||
|
# 更多文档整理中。。。
|
@ -32,8 +32,10 @@ class Topic {
|
|||||||
public DateTime CreateTime { get; set; }
|
public DateTime CreateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
var mysql = new MySql("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=3");
|
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||||
IUpdate<Topic> update => mysql.Update<Topic>();
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
|
.Build();
|
||||||
|
IUpdate<Topic> update => fsql.Update<Topic>();
|
||||||
```
|
```
|
||||||
|
|
||||||
### 动态条件
|
### 动态条件
|
||||||
@ -50,13 +52,13 @@ dywhere 支持
|
|||||||
|
|
||||||
### 更新指定列
|
### 更新指定列
|
||||||
```csharp
|
```csharp
|
||||||
var t1 = mysql.Update<Topic>(1).Set(a => a.CreateTime, DateTime.Now).ToSql();
|
var t1 = fsql.Update<Topic>(1).Set(a => a.CreateTime, DateTime.Now).ToSql();
|
||||||
//UPDATE `tb_topic` SET `CreateTime` = '2018-12-08 00:04:59' WHERE (`Id` = 1)
|
//UPDATE `tb_topic` SET `CreateTime` = '2018-12-08 00:04:59' WHERE (`Id` = 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 更新指定列,累加
|
### 更新指定列,累加
|
||||||
```csharp
|
```csharp
|
||||||
var t2 = mysql.Update<Topic>(1).Set(a => a.Clicks + 1).ToSql();
|
var t2 = fsql.Update<Topic>(1).Set(a => a.Clicks + 1).ToSql();
|
||||||
//UPDATE `tb_topic` SET `Clicks` = ifnull(`Clicks`,0) + 1 WHERE (`Id` = 1)
|
//UPDATE `tb_topic` SET `Clicks` = ifnull(`Clicks`,0) + 1 WHERE (`Id` = 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ namespace FreeSql.Tests.MySql {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ExecuteDeleted() {
|
public void ExecuteDeleted() {
|
||||||
|
|
||||||
Assert.Throws<NotImplementedException>(() => delete.Where(a => a.Id > 0).ExecuteDeleted());
|
delete.Where(a => a.Id > 0).ExecuteDeleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<AssemblyVersion>0.0.0.1</AssemblyVersion>
|
||||||
|
<Version>0.0.1</Version>
|
||||||
|
<FileVersion>0.0.0.0</FileVersion>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
78
readme.md
78
readme.md
@ -8,3 +8,81 @@
|
|||||||
* [CodeFirst 快速开发](Docs/codefirst.md)
|
* [CodeFirst 快速开发](Docs/codefirst.md)
|
||||||
* [DbFirst 快速开发](Docs/dbfirst.md)
|
* [DbFirst 快速开发](Docs/dbfirst.md)
|
||||||
* [DbFirst 生成器](Docs/generator.md)
|
* [DbFirst 生成器](Docs/generator.md)
|
||||||
|
|
||||||
|
# 查询数据
|
||||||
|
|
||||||
|
### 返回 List
|
||||||
|
```csharp
|
||||||
|
List<Topic> t1 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 返回 List + 导航属性的数据
|
||||||
|
```csharp
|
||||||
|
List<Topic> t5 = select.LeftJoin<TestTypeInfo>((a, b) => a.TypeGuid == b.Guid && b.Name == "111").ToList();
|
||||||
|
//此时会返回普通字段 + 导航对象 Type 的数据
|
||||||
|
```
|
||||||
|
|
||||||
|
### 指定字段返回
|
||||||
|
```csharp
|
||||||
|
//返回一个字段
|
||||||
|
List<int> t2 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => a.Id);
|
||||||
|
|
||||||
|
//返回匿名类
|
||||||
|
List<匿名类> t3 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList(a => new { a.Id, a.Title });
|
||||||
|
|
||||||
|
//返回元组
|
||||||
|
List<(int, string)> t4 = select.Where(a => a.Id > 0).Skip(100).Limit(200).ToList<(int, string)>("id, title");
|
||||||
|
```
|
||||||
|
|
||||||
|
### 执行SQL返回数据
|
||||||
|
```csharp
|
||||||
|
class xxx {
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string Title2 { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
List<xxx> t3 = fsql.Ado.Query<xxx>("select * from song");
|
||||||
|
List<(int, string ,string)> t4 = fsql.Ado.Query<(int, string, string)>("select * from song");
|
||||||
|
List<dynamic> t5 = fsql.Ado.Query<dynamic>("select * from song");
|
||||||
|
```
|
||||||
|
|
||||||
|
# 联表
|
||||||
|
|
||||||
|
### 使用导航属性联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid`
|
||||||
|
|
||||||
|
sql = select
|
||||||
|
.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
|
||||||
|
.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 没有导航属性联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON b.`Guid` = a.`TestTypeInfoGuid`
|
||||||
|
|
||||||
|
sql = select
|
||||||
|
.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
|
||||||
|
.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON b.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfo` c ON c.`Id` = b.`ParentId`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 联表任意查
|
||||||
|
```csharp
|
||||||
|
sql = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||||
|
.LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
|
||||||
|
.LeftJoin(a => b.ParentId == c.Id)).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, b.`Guid` as4, b.`ParentId` as5, b.`Name` as6, a.`Title` as7, a.`CreateTime` as8 FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON a.`TestTypeInfoGuid` = b.`Guid` LEFT JOIN `TestTypeParentInfo` c ON b.`ParentId` = c.`Id`
|
||||||
|
```
|
||||||
|
|
||||||
|
### 原生SQL联表
|
||||||
|
```csharp
|
||||||
|
sql = select.LeftJoin("TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname", new { bname = "xxx" }).ToSql();
|
||||||
|
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a LEFT JOIN TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname
|
||||||
|
```
|
||||||
|
|
||||||
|
# 更多文档整理中。。。
|
Loading…
x
Reference in New Issue
Block a user