From 8bbb7329f979ea8b976c58667140f084cb822c25 Mon Sep 17 00:00:00 2001
From: 2881099 <2881099@qq.com>
Date: Thu, 12 Nov 2020 06:35:29 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=20Async=20CancellationTo?=
=?UTF-8?q?ken=20IInsert/IUdate/IInsertOrUpdate=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql.DbContext/FreeSql.DbContext.xml | 16 ++
FreeSql/FreeSql.xml | 34 ++--
FreeSql/Interface/Curd/IInsert.cs | 7 +-
FreeSql/Interface/Curd/IInsertOrUpdate.cs | 3 +-
FreeSql/Interface/Curd/IUpdate.cs | 5 +-
FreeSql/Interface/IAdo.cs | 137 ++++++-------
.../AdoProvider/AdoProviderAsync.cs | 187 +++++++++---------
.../CommonProvider/InsertOrUpdateProvider.cs | 15 +-
.../CommonProvider/InsertProviderAsync.cs | 43 ++--
.../CommonProvider/UpdateProviderAsync.cs | 27 +--
FreeSql/Internal/Model/AdoCommandFluent.cs | 21 +-
.../Curd/DamengInsert.cs | 17 +-
.../Curd/DamengUpdate.cs | 7 +-
.../Curd/FirebirdInsert.cs | 21 +-
.../Curd/FirebirdUpdate.cs | 9 +-
.../Curd/KingbaseESInsert.cs | 17 +-
.../Curd/KingbaseESUpdate.cs | 9 +-
.../Curd/MsAccessInsert.cs | 25 +--
.../Curd/MsAccessUpdate.cs | 7 +-
.../Curd/MySqlInsert.cs | 15 +-
.../Curd/MySqlUpdate.cs | 9 +-
.../Dameng/Curd/OdbcDamengInsert.cs | 17 +-
.../Dameng/Curd/OdbcDamengUpdate.cs | 7 +-
.../Default/Curd/OdbcInsert.cs | 15 +-
.../Default/Curd/OdbcUpdate.cs | 7 +-
.../KingbaseES/Curd/OdbcKingbaseESInsert.cs | 17 +-
.../KingbaseES/Curd/OdbcKingbaseESUpdate.cs | 9 +-
.../MySql/Curd/OdbcMySqlInsert.cs | 17 +-
.../MySql/Curd/OdbcMySqlUpdate.cs | 9 +-
.../Oracle/Curd/OdbcOracleInsert.cs | 17 +-
.../Oracle/Curd/OdbcOracleUpdate.cs | 7 +-
.../PostgreSQL/Curd/OdbcPostgreSQLInsert.cs | 17 +-
.../PostgreSQL/Curd/OdbcPostgreSQLUpdate.cs | 9 +-
.../SqlServer/Curd/OdbcSqlServerInsert.cs | 15 +-
.../SqlServer/Curd/OdbcSqlServerUpdate.cs | 9 +-
.../Curd/OracleInsert.cs | 17 +-
.../Curd/OracleUpdate.cs | 7 +-
.../Curd/PostgreSQLInsert.cs | 17 +-
.../Curd/PostgreSQLUpdate.cs | 9 +-
.../Curd/ShenTongInsert.cs | 17 +-
.../Curd/ShenTongUpdate.cs | 9 +-
.../Curd/SqlServerInsert.cs | 15 +-
.../Curd/SqlServerUpdate.cs | 9 +-
.../Curd/SqliteInsert.cs | 15 +-
.../Curd/SqliteUpdate.cs | 7 +-
45 files changed, 492 insertions(+), 433 deletions(-)
diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index b3c14870..2d6d3409 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -130,6 +130,13 @@
清空状态数据
+
+
+ 根据 lambda 条件删除数据
+
+
+
+
添加
@@ -502,5 +509,14 @@
+
+
+ 批量注入 Repository,可以参考代码自行调整
+
+
+
+
+
+
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 3d1bfc1b..751d06c0 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -3013,7 +3013,7 @@
-
+
测试数据库是否连接正确,本方法执行如下命令:
MySql/SqlServer/PostgreSQL/达梦/人大金仓/神通: SELECT 1
@@ -3022,7 +3022,7 @@
命令超时设置(秒)
true: 成功, false: 失败
-
+
查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
@@ -3031,7 +3031,7 @@
-
+
查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3039,14 +3039,14 @@
-
+
查询
-
+
查询,ExecuteArrayAsync("select * from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3055,14 +3055,14 @@
-
+
查询
-
+
查询,ExecuteDataSetAsync("select * from user where age > ?age; select 2", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3071,14 +3071,14 @@
-
+
查询
-
+
查询,ExecuteDataTableAsync("select * from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3087,7 +3087,7 @@
-
+
在【主库】执行
@@ -3095,7 +3095,7 @@
-
+
在【主库】执行,ExecuteNonQueryAsync("delete from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3104,7 +3104,7 @@
-
+
在【主库】执行
@@ -3112,7 +3112,7 @@
-
+
在【主库】执行,ExecuteScalarAsync("select 1 from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3121,7 +3121,7 @@
-
+
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new SqlParameter { ParameterName = "age", Value = 25 })
@@ -3131,7 +3131,7 @@
-
+
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
@@ -3141,7 +3141,7 @@
-
+
执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
@@ -3151,7 +3151,7 @@
-
+
执行SQL返回对象集合,Query<User, Address>("select * from user where age > ?age; select * from address", new { age = 25 })
提示:parms 参数还可以传 Dictionary<string, object>
diff --git a/FreeSql/Interface/Curd/IInsert.cs b/FreeSql/Interface/Curd/IInsert.cs
index 234495ae..4cbcfd8c 100644
--- a/FreeSql/Interface/Curd/IInsert.cs
+++ b/FreeSql/Interface/Curd/IInsert.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq.Expressions;
+using System.Threading;
using System.Threading.Tasks;
namespace FreeSql
@@ -157,9 +158,9 @@ namespace FreeSql
#if net40
#else
- Task ExecuteAffrowsAsync();
- Task ExecuteIdentityAsync();
- Task> ExecuteInsertedAsync();
+ Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
+ Task ExecuteIdentityAsync(CancellationToken cancellationToken = default);
+ Task> ExecuteInsertedAsync(CancellationToken cancellationToken = default);
#endif
}
}
\ No newline at end of file
diff --git a/FreeSql/Interface/Curd/IInsertOrUpdate.cs b/FreeSql/Interface/Curd/IInsertOrUpdate.cs
index 0299d065..f2926980 100644
--- a/FreeSql/Interface/Curd/IInsertOrUpdate.cs
+++ b/FreeSql/Interface/Curd/IInsertOrUpdate.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
+using System.Threading;
using System.Threading.Tasks;
namespace FreeSql
@@ -86,7 +87,7 @@ namespace FreeSql
#if net40
#else
- Task ExecuteAffrowsAsync();
+ Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
#endif
}
}
\ No newline at end of file
diff --git a/FreeSql/Interface/Curd/IUpdate.cs b/FreeSql/Interface/Curd/IUpdate.cs
index 004939c3..87a372f7 100644
--- a/FreeSql/Interface/Curd/IUpdate.cs
+++ b/FreeSql/Interface/Curd/IUpdate.cs
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
+using System.Threading;
using System.Threading.Tasks;
namespace FreeSql
@@ -249,8 +250,8 @@ namespace FreeSql
#if net40
#else
- Task ExecuteAffrowsAsync();
- Task> ExecuteUpdatedAsync();
+ Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default);
+ Task> ExecuteUpdatedAsync(CancellationToken cancellationToken = default);
#endif
}
}
\ No newline at end of file
diff --git a/FreeSql/Interface/IAdo.cs b/FreeSql/Interface/IAdo.cs
index 69ce18f9..7e8f53f1 100644
--- a/FreeSql/Interface/IAdo.cs
+++ b/FreeSql/Interface/IAdo.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
namespace FreeSql
@@ -274,7 +275,7 @@ namespace FreeSql
///
/// 命令超时设置(秒)
/// true: 成功, false: 失败
- Task ExecuteConnectTestAsync(int commandTimeout = 0);
+ Task ExecuteConnectTestAsync(int commandTimeout = 0, CancellationToken cancellationToken = default);
///
/// 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
@@ -283,26 +284,26 @@ namespace FreeSql
///
///
///
- Task ExecuteReaderAsync(Func, Task> readerHander, CommandType cmdType, string cmdText, params DbParameter[] cmdParms);
- Task ExecuteReaderAsync(DbTransaction transaction, Func, Task> readerHander, CommandType cmdType, string cmdText, params DbParameter[] cmdParms);
- Task ExecuteReaderAsync(DbConnection connection, DbTransaction transaction, Func, Task> readerHander, CommandType cmdType, string cmdText, int cmdTimeout, params DbParameter[] cmdParms);
+ Task ExecuteReaderAsync(Func, Task> readerHander, CommandType cmdType, string cmdText, DbParameter[] cmdParms, CancellationToken cancellationToken = default);
+ Task ExecuteReaderAsync(DbTransaction transaction, Func, Task> readerHander, CommandType cmdType, string cmdText, DbParameter[] cmdParms, CancellationToken cancellationToken = default);
+ Task ExecuteReaderAsync(DbConnection connection, DbTransaction transaction, Func, Task> readerHander, CommandType cmdType, string cmdText, int cmdTimeout, DbParameter[] cmdParms, CancellationToken cancellationToken = default);
///
/// 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 })
/// 提示:parms 参数还可以传 Dictionary<string, object>
///
///
///
- Task ExecuteReaderAsync(Func, Task> readerHander, string cmdText, object parms = null);
- Task ExecuteReaderAsync(DbTransaction transaction, Func, Task> readerHander, string cmdText, object parms = null);
- Task ExecuteReaderAsync(DbConnection connection, DbTransaction transaction, Func, Task> readerHander, string cmdText, object parms = null);
+ Task ExecuteReaderAsync(Func, Task> readerHander, string cmdText, object parms = null, CancellationToken cancellationToken = default);
+ Task ExecuteReaderAsync(DbTransaction transaction, Func, Task> readerHander, string cmdText, object parms = null, CancellationToken cancellationToken = default);
+ Task ExecuteReaderAsync(DbConnection connection, DbTransaction transaction, Func, Task> readerHander, string cmdText, object parms = null, CancellationToken cancellationToken = default);
///
/// 查询
///
///
///
- Task