update

2881099
2020-11-26 18:28:55 +08:00
parent 523001bf58
commit 8057501449
12 changed files with 77 additions and 77 deletions

22
API.md

@@ -146,26 +146,26 @@ DbContext 自身 = 完整事务BaseRepository 不一定有事务(可通过
| 【条件】 | | 【条件】 |
| Where | \<this\> | Lambda | 支持多表查询表达式多次使用相当于AND | | Where | \<this\> | Lambda | 支持多表查询表达式多次使用相当于AND |
| WhereIf | \<this\> | bool, Lambda | 支持多表查询表达式 | | WhereIf | \<this\> | bool, Lambda | 支持多表查询表达式 |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| WhereIf | \<this\> | bool, string, parms | 原生sql语法条件WhereIf(true, "id = ?id", new { id = 1 }) | | WhereIf | \<this\> | bool, string, parms | 原生sql语法条件WhereIf(true, "id = @id", new { id = 1 }) |
| WhereCascade | \<this\> | Lambda | 实现多表查询时,向每个表中附加条件 | | WhereCascade | \<this\> | Lambda | 实现多表查询时,向每个表中附加条件 |
| 【分组】 | | 【分组】 |
| GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) | | GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) |
| GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, ?cc)", new { cc = 1 }) | | GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, @cc)", new { cc = 1 }) |
| Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = ?cc", new { cc = 1 }) | | Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = @cc", new { cc = 1 }) |
| Disdinct | \<this\> | | .Distinct().ToList(x => x.GroupName) 是对指定字段 | | Disdinct | \<this\> | | .Distinct().ToList(x => x.GroupName) 是对指定字段 |
| 【排序】 | | 【排序】 |
| OrderBy | \<this\> | Lambda | 按列排序OrderBy(a => a.Time),可多次使用 | | OrderBy | \<this\> | Lambda | 按列排序OrderBy(a => a.Time),可多次使用 |
| OrderByDescending | \<this\> | Lambda | 按列倒向排序OrderByDescending(a => a.Time) | | OrderByDescending | \<this\> | Lambda | 按列倒向排序OrderByDescending(a => a.Time) |
| OrderBy | \<this\> | string, parms | 按原生sql语法排序OrderBy("count(name) + ?cc", new { cc = 1 }) | | OrderBy | \<this\> | string, parms | 按原生sql语法排序OrderBy("count(name) + @cc", new { cc = 1 }) |
| OrderByPropertyName | string, bool | 按属性名字符串排序(支持导航属性) | | OrderByPropertyName | string, bool | 按属性名字符串排序(支持导航属性) |
| 【联表】 | | 【联表】 |
| LeftJoin | \<this\> | Lambda | 左联查询,可使用导航属性,或指定关联的实体类型 | | LeftJoin | \<this\> | Lambda | 左联查询,可使用导航属性,或指定关联的实体类型 |
| InnerJoin | \<this\> | Lambda | 联接查询,可使用导航属性,或指定关联的实体类型 | | InnerJoin | \<this\> | Lambda | 联接查询,可使用导航属性,或指定关联的实体类型 |
| RightJoin | \<this\> | Lambda | 右联查询,可使用导航属性,或指定关联的实体类型 | | RightJoin | \<this\> | Lambda | 右联查询,可使用导航属性,或指定关联的实体类型 |
| LeftJoin | \<this\> | string, parms | 左联查询使用原生sql语法LeftJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | LeftJoin | \<this\> | string, parms | 左联查询使用原生sql语法LeftJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| InnerJoin | \<this\> | string, parms | 联接查询使用原生sql语法InnerJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | InnerJoin | \<this\> | string, parms | 联接查询使用原生sql语法InnerJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| RightJoin | \<this\> | string, parms | 右联查询使用原生sql语法RightJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | RightJoin | \<this\> | string, parms | 右联查询使用原生sql语法RightJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| From | \<this\> | Lambda | 多表查询3个表以上使用非常方便目前设计最大支持10个表 | | From | \<this\> | Lambda | 多表查询3个表以上使用非常方便目前设计最大支持10个表 |
| 【其他】 | | 【其他】 |
| As | \<this\> | string alias = "a" | 指定别名 | | As | \<this\> | string alias = "a" | 指定别名 |
@@ -219,9 +219,9 @@ DbContext 自身 = 完整事务BaseRepository 不一定有事务(可通过
| Set | \<this\> | Lambda, value | 设置列的新值Set(a => a.Name, "newvalue") | | Set | \<this\> | Lambda, value | 设置列的新值Set(a => a.Name, "newvalue") |
| Set | \<this\> | Lambda | 设置列的的新值为基础上增加Set(a => a.Clicks + 1),相当于 clicks=clicks+1 | | Set | \<this\> | Lambda | 设置列的的新值为基础上增加Set(a => a.Clicks + 1),相当于 clicks=clicks+1 |
| SetDto | \<this\> | object | 根据 dto 更新的方法 | | SetDto | \<this\> | object | 根据 dto 更新的方法 |
| SetRaw | \<this\> | string, parms | 设置值自定义SQL语法SetRaw("title = ?title", new { title = "newtitle" }) | | SetRaw | \<this\> | string, parms | 设置值自定义SQL语法SetRaw("title = @title", new { title = "newtitle" }) |
| Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) | | Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 | | Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 | | WhereExists | \<this\> | ISelect | 子查询是否存在 |
| CommandTimeout | \<this\> | int | 命令超时设置(秒) | | CommandTimeout | \<this\> | int | 命令超时设置(秒) |
@@ -238,7 +238,7 @@ DbContext 自身 = 完整事务BaseRepository 不一定有事务(可通过
| 方法 | 返回值 | 参数 | 描述 | | 方法 | 返回值 | 参数 | 描述 |
| - | - | - | - | | - | - | - | - |
| Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) | | Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 | | Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 | | WhereExists | \<this\> | ISelect | 子查询是否存在 |
| CommandTimeout | \<this\> | int | 命令超时设置(秒) | | CommandTimeout | \<this\> | int | 命令超时设置(秒) |

@@ -78,7 +78,7 @@ var repo = fsql.GetRepository<Topic>();
var item = repo.Where(a => a.Id == 1).First(); //此时快照 item var item = repo.Where(a => a.Id == 1).First(); //此时快照 item
item.Title = "newtitle"; item.Title = "newtitle";
repo.Update(item); //对比快照时的变化 repo.Update(item); //对比快照时的变化
//UPDATE `tb_topic` SET `Title` = ?p_0 //UPDATE `tb_topic` SET `Title` = @p_0
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
``` ```
@@ -89,7 +89,7 @@ var item = new Topic { Id = 1 };
repo.Attach(item); //此时快照 item repo.Attach(item); //此时快照 item
item.Title = "newtitle"; item.Title = "newtitle";
repo.Update(item); //对比快照时的变化 repo.Update(item); //对比快照时的变化
//UPDATE `tb_topic` SET `Title` = ?p_0 //UPDATE `tb_topic` SET `Title` = @p_0
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
``` ```

@@ -69,7 +69,7 @@ fsql.Update<Topic>()
.Set(a => a.Time, DateTime.Now) .Set(a => a.Time, DateTime.Now)
.Where(a => a.Id == 1) .Where(a => a.Id == 1)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Title` = ?p_0, `Time` = ?p_1 //UPDATE `Topic` SET `Title` = @p_0, `Time` = @p_1
//WHERE (Id = 1) //WHERE (Id = 1)
``` ```
@@ -83,7 +83,7 @@ var repo = fsql.GetRepository<Topic>();
var item = repo.Where(a => a.Id == 1).First(); //此时快照 item var item = repo.Where(a => a.Id == 1).First(); //此时快照 item
item.Title = "newtitle"; item.Title = "newtitle";
repo.Update(item); //对比快照时的变化 repo.Update(item); //对比快照时的变化
//UPDATE `Topic` SET `Title` = ?p_0 //UPDATE `Topic` SET `Title` = @p_0
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
``` ```
@@ -94,7 +94,7 @@ var item = new Topic { Id = 1 };
repo.Attach(item); //此时快照 item repo.Attach(item); //此时快照 item
item.Title = "newtitle"; item.Title = "newtitle";
repo.Update(item); //对比快照时的变化 repo.Update(item); //对比快照时的变化
//UPDATE `Topic` SET `Title` = ?p_0 //UPDATE `Topic` SET `Title` = @p_0
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
``` ```
@@ -112,21 +112,21 @@ var item = new Topic { Id = 1, Title = "newtitle" };
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(item) .SetSource(item)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Clicks` = ?p_0, `Title` = ?p_1, `CreateTime` = ?p_2 //UPDATE `Topic` SET `Clicks` = @p_0, `Title` = @p_1, `CreateTime` = @p_2
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(item) .SetSource(item)
.UpdateColumns(a => new { a.Title, a.CreateTime }) .UpdateColumns(a => new { a.Title, a.CreateTime })
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Title` = ?p_0, `CreateTime` = ?p_1 //UPDATE `Topic` SET `Title` = @p_0, `CreateTime` = @p_1
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(item) .SetSource(item)
.IgnoreColumns(a => new { a.Clicks, a.CreateTime }) .IgnoreColumns(a => new { a.Clicks, a.CreateTime })
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Title` = ?p_0 //UPDATE `Topic` SET `Title` = @p_0
//WHERE (`Id` = 1) //WHERE (`Id` = 1)
var items = new List<Topic>(); var items = new List<Topic>();
@@ -135,23 +135,23 @@ for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitl
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(items) .SetSource(items)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Clicks` = CASE `Id` WHEN 1 THEN ?p_0 WHEN 2 THEN ?p_1 WHEN 3 THEN ?p_2 WHEN 4 THEN ?p_3 WHEN 5 THEN ?p_4 WHEN 6 THEN ?p_5 WHEN 7 THEN ?p_6 WHEN 8 THEN ?p_7 WHEN 9 THEN ?p_8 WHEN 10 THEN ?p_9 END, //UPDATE `Topic` SET `Clicks` = CASE `Id` WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END,
//`Title` = CASE `Id` WHEN 1 THEN ?p_10 WHEN 2 THEN ?p_11 WHEN 3 THEN ?p_12 WHEN 4 THEN ?p_13 WHEN 5 THEN ?p_14 WHEN 6 THEN ?p_15 WHEN 7 THEN ?p_16 WHEN 8 THEN ?p_17 WHEN 9 THEN ?p_18 WHEN 10 THEN ?p_19 END, //`Title` = CASE `Id` WHEN 1 THEN @p_10 WHEN 2 THEN @p_11 WHEN 3 THEN @p_12 WHEN 4 THEN @p_13 WHEN 5 THEN @p_14 WHEN 6 THEN @p_15 WHEN 7 THEN @p_16 WHEN 8 THEN @p_17 WHEN 9 THEN @p_18 WHEN 10 THEN @p_19 END,
//`CreateTime` = CASE `Id` WHEN 1 THEN ?p_20 WHEN 2 THEN ?p_21 WHEN 3 THEN ?p_22 WHEN 4 THEN ?p_23 WHEN 5 THEN ?p_24 WHEN 6 THEN ?p_25 WHEN 7 THEN ?p_26 WHEN 8 THEN ?p_27 WHEN 9 THEN ?p_28 WHEN 10 THEN ?p_29 END //`CreateTime` = CASE `Id` WHEN 1 THEN @p_20 WHEN 2 THEN @p_21 WHEN 3 THEN @p_22 WHEN 4 THEN @p_23 WHEN 5 THEN @p_24 WHEN 6 THEN @p_25 WHEN 7 THEN @p_26 WHEN 8 THEN @p_27 WHEN 9 THEN @p_28 WHEN 10 THEN @p_29 END
//WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10)) //WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(items) .SetSource(items)
.IgnoreColumns(a => new { a.Clicks, a.CreateTime }) .IgnoreColumns(a => new { a.Clicks, a.CreateTime })
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Title` = CASE `Id` WHEN 1 THEN ?p_0 WHEN 2 THEN ?p_1 WHEN 3 THEN ?p_2 WHEN 4 THEN ?p_3 WHEN 5 THEN ?p_4 WHEN 6 THEN ?p_5 WHEN 7 THEN ?p_6 WHEN 8 THEN ?p_7 WHEN 9 THEN ?p_8 WHEN 10 THEN ?p_9 END //UPDATE `Topic` SET `Title` = CASE `Id` WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END
//WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10)) //WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))
fsql.Update<Topic>() fsql.Update<Topic>()
.SetSource(items) .SetSource(items)
.Set(a => a.CreateTime, DateTime.Now) .Set(a => a.CreateTime, DateTime.Now)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `CreateTime` = ?p_0 //UPDATE `Topic` SET `CreateTime` = @p_0
//WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10)) //WHERE (`Id` IN (1,2,3,4,5,6,7,8,9,10))
``` ```
@@ -161,10 +161,10 @@ fsql.Update<Topic>()
```csharp ```csharp
fsql.Update<Topic>() fsql.Update<Topic>()
.SetRaw("Title = ?title", new { title = "新标题" }) .SetRaw("Title = @title", new { title = "新标题" })
.Where("Id = ?id", 1) .Where("Id = @id", 1)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET Title = ?title WHERE (Id = ?id) //UPDATE `Topic` SET Title = @title WHERE (Id = @id)
``` ```
## 5、根据 Dto 更新 ## 5、根据 Dto 更新
@@ -174,7 +174,7 @@ fsql.Update<T>()
.SetDto(new { title = "xxx", clicks = 2 }) .SetDto(new { title = "xxx", clicks = 2 })
.Where(a => a.Id == 1) .Where(a => a.Id == 1)
.ExecuteAffrows(); .ExecuteAffrows();
//UPDATE `Topic` SET `Title` = ?p_0, `Clicks` = ?p_1 WHERE (Id = 1) //UPDATE `Topic` SET `Title` = @p_0, `Clicks` = @p_1 WHERE (Id = 1)
fsql.Update<T>() fsql.Update<T>()
.SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 }) .SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 })
@@ -258,9 +258,9 @@ UPDATE `T1` SET Title = '111' WHERE id in (select a.id from T1 a left join Optio
| Set | \<this\> | Lambda, value | 设置列的新值Set(a => a.Name, "newvalue") | | Set | \<this\> | Lambda, value | 设置列的新值Set(a => a.Name, "newvalue") |
| Set | \<this\> | Lambda | 设置列的的新值为基础上增加Set(a => a.Clicks + 1),相当于 clicks=clicks+1 | | Set | \<this\> | Lambda | 设置列的的新值为基础上增加Set(a => a.Clicks + 1),相当于 clicks=clicks+1 |
| SetDto | \<this\> | object | 根据 dto 更新的方法 | | SetDto | \<this\> | object | 根据 dto 更新的方法 |
| SetRaw | \<this\> | string, parms | 设置值自定义SQL语法SetRaw("title = ?title", new { title = "newtitle" }) | | SetRaw | \<this\> | string, parms | 设置值自定义SQL语法SetRaw("title = @title", new { title = "newtitle" }) |
| Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) | | Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 | | Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 | | WhereExists | \<this\> | ISelect | 子查询是否存在 |
| CommandTimeout | \<this\> | int | 命令超时设置(秒) | | CommandTimeout | \<this\> | int | 命令超时设置(秒) |

@@ -45,8 +45,8 @@ var list = fsql.Select<Topic>()
| Avg | T | Lambda | 指定一个列求平均值 | | Avg | T | Lambda | 指定一个列求平均值 |
| 【分组】 | | 【分组】 |
| GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) | | GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) |
| GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, ?cc)", new { cc = 1 }) | | GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, @cc)", new { cc = 1 }) |
| Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = ?cc", new { cc = 1 }) | | Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = @cc", new { cc = 1 }) |
| 【成员】 | | 【成员】 |
| Key | | | 返回 GroupBy 选择的对象 | | Key | | | 返回 GroupBy 选择的对象 |
| Value | | | 返回主表 或 From\<T2,T3....\> 的字段选择器 | | Value | | | 返回主表 或 From\<T2,T3....\> 的字段选择器 |

@@ -51,8 +51,8 @@ var t4 = fsql.Delete<Topic>(new { id = 1 }).ToSql();
var t5 = fsql.Delete<Topic>().Where(a => a.Id == 1).ToSql(); var t5 = fsql.Delete<Topic>().Where(a => a.Id == 1).ToSql();
//DELETE FROM `Topic` WHERE (`Id` = 1) //DELETE FROM `Topic` WHERE (`Id` = 1)
var t6 = fsql.Delete<Topic>().Where("id = ?id", new { id = 1 }).ToSql(); var t6 = fsql.Delete<Topic>().Where("id = @id", new { id = 1 }).ToSql();
//DELETE FROM `Topic` WHERE (id = ?id) //DELETE FROM `Topic` WHERE (id = @id)
var item = new Topic { Id = 1, Title = "newtitle" }; var item = new Topic { Id = 1, Title = "newtitle" };
var t7 = fsql.Delete<Topic>().Where(item).ToSql(); var t7 = fsql.Delete<Topic>().Where(item).ToSql();
@@ -96,7 +96,7 @@ DELETE FROM `T1` WHERE id in (select a.id from T1 a left join Options b on b.t1i
| 方法 | 返回值 | 参数 | 描述 | | 方法 | 返回值 | 参数 | 描述 |
| - | - | - | - | | - | - | - | - |
| Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) | | Where | \<this\> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 | | Where | \<this\> | T1 \| IEnumerable\<T1\> | 传入实体或集合,将其主键作为条件 |
| WhereExists | \<this\> | ISelect | 子查询是否存在 | | WhereExists | \<this\> | ISelect | 子查询是否存在 |
| CommandTimeout | \<this\> | int | 命令超时设置(秒) | | CommandTimeout | \<this\> | int | 命令超时设置(秒) |

@@ -41,11 +41,11 @@ fsql.Select<Topic>()
## WithSql ## WithSql
```csharp ```csharp
fsql.Select<Topic>() fsql.Select<Topic>()
.WithSql("select * from Topic where clicks > ?val", new { val = 10 }) .WithSql("select * from Topic where clicks > @val", new { val = 10 })
.Page(1, 10) .Page(1, 10)
.ToList() .ToList()
//SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime` //SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime`
//FROM (select * from Topic where clicks > ?val) a //FROM (select * from Topic where clicks > @val) a
``` ```
> WithSql 使用多次为 UNION ALL 查询 > WithSql 使用多次为 UNION ALL 查询

@@ -77,8 +77,8 @@ fsql.Select<Topic, Category, CategoryType>()
```csharp ```csharp
fsql.Select<Topic, Category, CategoryType>() fsql.Select<Topic, Category, CategoryType>()
.WithSql( .WithSql(
"select * from Topic where id=?id1", "select * from Topic where id=@id1",
"select * from Category where id=?id2", "select * from Category where id=@id2",
null, //不设置 CategoryType 对应的 SQL null, //不设置 CategoryType 对应的 SQL
new { id1 = 10, id2 = 11, id3 = 13 } new { id1 = 10, id2 = 11, id3 = 13 }
) )
@@ -86,19 +86,19 @@ fsql.Select<Topic, Category, CategoryType>()
.LeftJoin((a,b,c) => b.ParentId == c.Id) .LeftJoin((a,b,c) => b.ParentId == c.Id)
.ToList(); .ToList();
//SELECT ... //SELECT ...
//FROM ( select * from Topic where id=?id1 ) a //FROM ( select * from Topic where id=@id1 ) a
//LEFT JOIN ( select * from Category where id=?id2 ) b ON a.`CategoryId` = b.`Id` //LEFT JOIN ( select * from Category where id=@id2 ) b ON a.`CategoryId` = b.`Id`
//LEFT JOIN `CategoryType` c ON b.`ParentId` = c.`Id` //LEFT JOIN `CategoryType` c ON b.`ParentId` = c.`Id`
``` ```
## 4、SQL联表 ## 4、SQL联表
```csharp ```csharp
fsql.Select<Topic>() fsql.Select<Topic>()
.LeftJoin("Category b on b.Id = a.CategoryId and b.Name = ?bname", new { bname = "xxx" }) .LeftJoin("Category b on b.Id = a.CategoryId and b.Name = @bname", new { bname = "xxx" })
.ToList(); .ToList();
//SELECT a.`Id`, a.`Title`, a.`Clicks`, a.`CreateTime`, a.`CategoryId` //SELECT a.`Id`, a.`Title`, a.`Clicks`, a.`CreateTime`, a.`CategoryId`
//FROM `Topic` a //FROM `Topic` a
//LEFT JOIN Category b on b.Id = a.CategoryId and b.Name = ?bname //LEFT JOIN Category b on b.Id = a.CategoryId and b.Name = @bname
``` ```
延伸问题SQL联表 b 表的字段如何在 ToList 中指定? 延伸问题SQL联表 b 表的字段如何在 ToList 中指定?

@@ -98,27 +98,27 @@ fsql.Select<VM_District_Parent>().WhereDynamicFilter(dyfilter).ToList();
| 【条件】 | | 【条件】 |
| Where | \<this\> | Lambda | 支持多表查询表达式多次使用相当于AND | | Where | \<this\> | Lambda | 支持多表查询表达式多次使用相当于AND |
| WhereIf | \<this\> | bool, Lambda | 支持多表查询表达式 | | WhereIf | \<this\> | bool, Lambda | 支持多表查询表达式 |
| Where | \<this\> | string, parms | 原生sql语法条件Where("id = ?id", new { id = 1 }) | | Where | \<this\> | string, parms | 原生sql语法条件Where("id = @id", new { id = 1 }) |
| WhereIf | \<this\> | bool, string, parms | 原生sql语法条件WhereIf(true, "id = ?id", new { id = 1 }) | | WhereIf | \<this\> | bool, string, parms | 原生sql语法条件WhereIf(true, "id = @id", new { id = 1 }) |
| WhereCascade | \<this\> | Lambda | 实现多表查询时,向每个表中附加条件 | | WhereCascade | \<this\> | Lambda | 实现多表查询时,向每个表中附加条件 |
| WhereDynamicFilter | \<this\> | DynamicFilterInfo | 动态过滤条件(与前端交互) | | WhereDynamicFilter | \<this\> | DynamicFilterInfo | 动态过滤条件(与前端交互) |
| 【分组】 | | 【分组】 |
| GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) | | GroupBy | \<this\> | Lambda | 按选择的列分组GroupBy(a => a.Name) | GroupBy(a => new{a.Name,a.Time}) |
| GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, ?cc)", new { cc = 1 }) | | GroupBy | \<this\> | string, parms | 按原生sql语法分组GroupBy("concat(name, @cc)", new { cc = 1 }) |
| Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = ?cc", new { cc = 1 }) | | Having | \<this\> | string, parms | 按原生sql语法聚合条件过滤Having("count(name) = @cc", new { cc = 1 }) |
| Disdinct | \<this\> | | .Distinct().ToList(x => x.GroupName) 是对指定字段 | | Disdinct | \<this\> | | .Distinct().ToList(x => x.GroupName) 是对指定字段 |
| 【排序】 | | 【排序】 |
| OrderBy | \<this\> | Lambda | 按列排序OrderBy(a => a.Time),可多次使用 | | OrderBy | \<this\> | Lambda | 按列排序OrderBy(a => a.Time),可多次使用 |
| OrderByDescending | \<this\> | Lambda | 按列倒向排序OrderByDescending(a => a.Time) | | OrderByDescending | \<this\> | Lambda | 按列倒向排序OrderByDescending(a => a.Time) |
| OrderBy | \<this\> | string, parms | 按原生sql语法排序OrderBy("count(name) + ?cc", new { cc = 1 }) | | OrderBy | \<this\> | string, parms | 按原生sql语法排序OrderBy("count(name) + @cc", new { cc = 1 }) |
| OrderByPropertyName | string, bool | 按属性名字符串排序(支持导航属性) | | OrderByPropertyName | string, bool | 按属性名字符串排序(支持导航属性) |
| 【联表】 | | 【联表】 |
| LeftJoin | \<this\> | Lambda | 左联查询,可使用导航属性,或指定关联的实体类型 | | LeftJoin | \<this\> | Lambda | 左联查询,可使用导航属性,或指定关联的实体类型 |
| InnerJoin | \<this\> | Lambda | 联接查询,可使用导航属性,或指定关联的实体类型 | | InnerJoin | \<this\> | Lambda | 联接查询,可使用导航属性,或指定关联的实体类型 |
| RightJoin | \<this\> | Lambda | 右联查询,可使用导航属性,或指定关联的实体类型 | | RightJoin | \<this\> | Lambda | 右联查询,可使用导航属性,或指定关联的实体类型 |
| LeftJoin | \<this\> | string, parms | 左联查询使用原生sql语法LeftJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | LeftJoin | \<this\> | string, parms | 左联查询使用原生sql语法LeftJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| InnerJoin | \<this\> | string, parms | 联接查询使用原生sql语法InnerJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | InnerJoin | \<this\> | string, parms | 联接查询使用原生sql语法InnerJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| RightJoin | \<this\> | string, parms | 右联查询使用原生sql语法RightJoin("type b on b.id = a.id and b.clicks > ?clicks", new { clicks = 1 }) | | RightJoin | \<this\> | string, parms | 右联查询使用原生sql语法RightJoin("type b on b.id = a.id and b.clicks > @clicks", new { clicks = 1 }) |
| From | \<this\> | Lambda | 多表查询3个表以上使用非常方便目前设计最大支持10个表 | | From | \<this\> | Lambda | 多表查询3个表以上使用非常方便目前设计最大支持10个表 |
| 【其他】 | | 【其他】 |
| As | \<this\> | string alias = "a" | 指定别名 | | As | \<this\> | string alias = "a" | 指定别名 |

@@ -26,7 +26,7 @@ for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitl
```csharp ```csharp
var t1 = fsql.Insert(items.First()).ExecuteAffrows(); var t1 = fsql.Insert(items.First()).ExecuteAffrows();
//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`) //INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`)
//VALUES(?Clicks0, ?Title0, ?CreateTime0) //VALUES(@Clicks0, @Title0, @CreateTime0)
``` ```
如果表有自增列,插入数据后应该要返回 id。 如果表有自增列,插入数据后应该要返回 id。
@@ -49,11 +49,11 @@ repo.Insert(blog);
```csharp ```csharp
var t2 = fsql.Insert(items).ExecuteAffrows(); var t2 = fsql.Insert(items).ExecuteAffrows();
//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`) //INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`)
//VALUES(?Clicks0, ?Title0, ?CreateTime0), (?Clicks1, ?Title1, ?CreateTime1), //VALUES(@Clicks0, @Title0, @CreateTime0), (@Clicks1, @Title1, @CreateTime1),
//(?Clicks2, ?Title2, ?CreateTime2), (?Clicks3, ?Title3, ?CreateTime3), //(@Clicks2, @Title2, @CreateTime2), (@Clicks3, @Title3, @CreateTime3),
//(?Clicks4, ?Title4, ?CreateTime4), (?Clicks5, ?Title5, ?CreateTime5), //(@Clicks4, @Title4, @CreateTime4), (@Clicks5, @Title5, @CreateTime5),
//(?Clicks6, ?Title6, ?CreateTime6), (?Clicks7, ?Title7, ?CreateTime7), //(@Clicks6, @Title6, @CreateTime6), (@Clicks7, @Title7, @CreateTime7),
//(?Clicks8, ?Title8, ?CreateTime8), (?Clicks9, ?Title9, ?CreateTime9) //(@Clicks8, @Title8, @CreateTime8), (@Clicks9, @Title9, @CreateTime9)
``` ```
> 解决了 SqlServer 批量添加容易导致的错误:传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。 > 解决了 SqlServer 批量添加容易导致的错误:传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
@@ -112,15 +112,15 @@ Bulk Copy 操作以扩展方法的形式实现,针对 SqlServer/PostgreSQL/MyS
```csharp ```csharp
var t3 = fsql.Insert(items).InsertColumns(a => a.Title).ExecuteAffrows(); var t3 = fsql.Insert(items).InsertColumns(a => a.Title).ExecuteAffrows();
//INSERT INTO `Topic`(`Title`) //INSERT INTO `Topic`(`Title`)
//VALUES(?Title0), (?Title1), (?Title2), (?Title3), (?Title4), //VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4),
//(?Title5), (?Title6), (?Title7), (?Title8), (?Title9) //(@Title5), (@Title6), (@Title7), (@Title8), (@Title9)
var t4 = fsql.Insert(items).InsertColumns(a =>new { a.Title, a.Clicks }).ExecuteAffrows(); var t4 = fsql.Insert(items).InsertColumns(a =>new { a.Title, a.Clicks }).ExecuteAffrows();
//INSERT INTO `Topic`(`Clicks`, `Title`) //INSERT INTO `Topic`(`Clicks`, `Title`)
//VALUES(?Clicks0, ?Title0), (?Clicks1, ?Title1), (?Clicks2, ?Title2), //VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2),
//(?Clicks3, ?Title3), (?Clicks4, ?Title4), (?Clicks5, ?Title5), //(@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5),
//(?Clicks6, ?Title6), (?Clicks7, ?Title7), (?Clicks8, ?Title8), //(@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8),
//(?Clicks9, ?Title9) //(@Clicks9, @Title9)
``` ```
## 5、忽略列 ## 5、忽略列
@@ -128,15 +128,15 @@ var t4 = fsql.Insert(items).InsertColumns(a =>new { a.Title, a.Clicks }).Execute
```csharp ```csharp
var t5 = fsql.Insert(items).IgnoreColumns(a => a.CreateTime).ExecuteAffrows(); var t5 = fsql.Insert(items).IgnoreColumns(a => a.CreateTime).ExecuteAffrows();
//INSERT INTO `Topic`(`Clicks`, `Title`) //INSERT INTO `Topic`(`Clicks`, `Title`)
//VALUES(?Clicks0, ?Title0), (?Clicks1, ?Title1), (?Clicks2, ?Title2), //VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2),
//(?Clicks3, ?Title3), (?Clicks4, ?Title4), (?Clicks5, ?Title5), //(@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5),
//(?Clicks6, ?Title6), (?Clicks7, ?Title7), (?Clicks8, ?Title8), //(@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8),
//(?Clicks9, ?Title9) //(@Clicks9, @Title9)
var t6 = fsql.Insert(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ExecuteAffrows(); var t6 = fsql.Insert(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ExecuteAffrows();
///INSERT INTO `Topic`(`Clicks`) ///INSERT INTO `Topic`(`Clicks`)
//VALUES(?Clicks0), (?Clicks1), (?Clicks2), (?Clicks3), (?Clicks4), //VALUES(@Clicks0), (@Clicks1), (@Clicks2), (@Clicks3), (@Clicks4),
//(?Clicks5), (?Clicks6), (?Clicks7), (?Clicks8), (?Clicks9) //(@Clicks5), (@Clicks6), (@Clicks7), (@Clicks8), (@Clicks9)
``` ```
## 6、列插入优先级 ## 6、列插入优先级
@@ -176,8 +176,8 @@ limit 10
```csharp ```csharp
fsql.Insert<Topic>().MySqlIgnoreInto().AppendData(items).ExecuteAffrows(); fsql.Insert<Topic>().MySqlIgnoreInto().AppendData(items).ExecuteAffrows();
///INSERT IGNORE INTO `Topic`(`Clicks`) ///INSERT IGNORE INTO `Topic`(`Clicks`)
//VALUES(?Clicks0), (?Clicks1), (?Clicks2), (?Clicks3), (?Clicks4), //VALUES(@Clicks0), (@Clicks1), (@Clicks2), (@Clicks3), (@Clicks4),
//(?Clicks5), (?Clicks6), (?Clicks7), (?Clicks8), (?Clicks9) //(@Clicks5), (@Clicks6), (@Clicks7), (@Clicks8), (@Clicks9)
``` ```
## 9、MySql 特有功能 On Duplicate Key Update ## 9、MySql 特有功能 On Duplicate Key Update

@@ -157,7 +157,7 @@ var fsql = new FreeSqlBuilder() //请务必定义成 Singleton 单例模式
var id = 1; var id = 1;
fsql.Select<Song>().Where(a => a.Id == id).ToList(); fsql.Select<Song>().Where(a => a.Id == id).ToList();
//SELECT .. FROM `Song` a WHERE `Id` = ?exp_0 //SELECT .. FROM `Song` a WHERE `Id` = @exp_0
``` ```
生成的参数对象DbType、Size、Precision、Scale 值设置默认已作优化,与实体属性定义一致。 生成的参数对象DbType、Size、Precision、Scale 值设置默认已作优化,与实体属性定义一致。

@@ -91,11 +91,11 @@ List<dynamic> t13 = fsql.Ado.Query<dynamic>("select * from song");
## 9、WithSql ## 9、WithSql
```csharp ```csharp
fsql.Select<Topic>() fsql.Select<Topic>()
.WithSql("select * from Topic where clicks > ?val", new { val = 10 }) .WithSql("select * from Topic where clicks > @val", new { val = 10 })
.Page(1, 10) .Page(1, 10)
.ToList() .ToList()
//SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime` //SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime`
//FROM (select * from Topic where clicks > ?val) a //FROM (select * from Topic where clicks > @val) a
``` ```
> WithSql 使用多次为 UNION ALL 查询 > WithSql 使用多次为 UNION ALL 查询

@@ -15,7 +15,7 @@ FreeSql CodeFirst 支持将 c# 代码内的注释,迁移至数据库的备注
这个方法可以设置不使用 参数化 执行 SQL 命令,方便开发调试。 这个方法可以设置不使用 参数化 执行 SQL 命令,方便开发调试。
```sql ```sql
INSERT INTO `tb_topic`(`Title`) VALUES(?Title0) INSERT INTO `tb_topic`(`Title`) VALUES(@Title0)
INSERT INTO `tb_topic`(`Title`) VALUES('Title_1') INSERT INTO `tb_topic`(`Title`) VALUES('Title_1')
``` ```
@@ -40,11 +40,11 @@ repo.InsertOrUpdate(实体);
# 4、WithSql # 4、WithSql
```csharp ```csharp
fsql.Select<Topic>() fsql.Select<Topic>()
.WithSql("select * from Topic where clicks > ?val", new { val = 10 }) .WithSql("select * from Topic where clicks > @val", new { val = 10 })
.Page(1, 10) .Page(1, 10)
.ToList() .ToList()
//SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime` //SELECT a.`Id`, a.`Clicks`, a.`CategoryId`, a.`Title`, a.`CreateTime`
//FROM (select * from Topic where clicks > ?val) a //FROM (select * from Topic where clicks > @val) a
``` ```
> WithSql 使用多次为 UNION ALL 查询 > WithSql 使用多次为 UNION ALL 查询