mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 增加 Async CancellationToken ISelect;
This commit is contained in:
@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
#if MySqlConnector
|
||||
using MySqlConnector;
|
||||
#else
|
||||
@ -89,7 +90,7 @@ public static class FreeSqlMySqlConnectorGlobalExtensions
|
||||
}
|
||||
#if net40
|
||||
#else
|
||||
async public static Task ExecuteMySqlBulkCopyAsync<T>(this IInsert<T> that, int? bulkCopyTimeout = null) where T : class
|
||||
async public static Task ExecuteMySqlBulkCopyAsync<T>(this IInsert<T> that, int? bulkCopyTimeout = null, CancellationToken cancellationToken = default) where T : class
|
||||
{
|
||||
var insert = that as FreeSql.MySql.Curd.MySqlInsert<T>;
|
||||
if (insert == null) throw new Exception("ExecuteMySqlBulkCopyAsync 是 FreeSql.Provider.MySqlConnector 特有的功能");
|
||||
@ -101,7 +102,7 @@ public static class FreeSqlMySqlConnectorGlobalExtensions
|
||||
{
|
||||
if (bulkCopyTimeout.HasValue) bulkCopy.BulkCopyTimeout = bulkCopyTimeout.Value;
|
||||
bulkCopy.DestinationTableName = dt.TableName;
|
||||
return bulkCopy.WriteToServerAsync(dt);
|
||||
return bulkCopy.WriteToServerAsync(dt, cancellationToken);
|
||||
};
|
||||
|
||||
try
|
||||
@ -124,7 +125,7 @@ public static class FreeSqlMySqlConnectorGlobalExtensions
|
||||
if (conn.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
isNotOpen = true;
|
||||
conn.Open();
|
||||
await conn.OpenAsync(cancellationToken);
|
||||
}
|
||||
try
|
||||
{
|
||||
@ -133,7 +134,7 @@ public static class FreeSqlMySqlConnectorGlobalExtensions
|
||||
finally
|
||||
{
|
||||
if (isNotOpen)
|
||||
conn.Close();
|
||||
await conn.CloseAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Data;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public static partial class FreeSqlPostgreSQLGlobalExtensions
|
||||
@ -119,7 +120,7 @@ public static partial class FreeSqlPostgreSQLGlobalExtensions
|
||||
|
||||
#if net45
|
||||
#else
|
||||
async public static Task ExecutePgCopyAsync<T>(this IInsert<T> that) where T : class
|
||||
async public static Task ExecutePgCopyAsync<T>(this IInsert<T> that, CancellationToken cancellationToken = default) where T : class
|
||||
{
|
||||
var insert = that as FreeSql.PostgreSQL.Curd.PostgreSQLInsert<T>;
|
||||
if (insert == null) throw new Exception("ExecutePgCopyAsync 是 FreeSql.Provider.PostgreSQL 特有的功能");
|
||||
@ -139,7 +140,7 @@ public static partial class FreeSqlPostgreSQLGlobalExtensions
|
||||
using (var writer = conn.BeginBinaryImport(copyFromCommand.ToString()))
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
await writer.WriteRowAsync(System.Threading.CancellationToken.None, item.ItemArray);
|
||||
await writer.WriteRowAsync(cancellationToken, item.ItemArray);
|
||||
writer.Complete();
|
||||
}
|
||||
copyFromCommand.Clear();
|
||||
@ -165,7 +166,7 @@ public static partial class FreeSqlPostgreSQLGlobalExtensions
|
||||
if (conn.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
isNotOpen = true;
|
||||
await conn.OpenAsync();
|
||||
await conn.OpenAsync(cancellationToken);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
#if microsoft
|
||||
using Microsoft.Data.SqlClient;
|
||||
#else
|
||||
@ -146,7 +147,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
}
|
||||
#if net40
|
||||
#else
|
||||
async public static Task ExecuteSqlBulkCopyAsync<T>(this IInsert<T> that, SqlBulkCopyOptions copyOptions = SqlBulkCopyOptions.Default, int? batchSize = null, int? bulkCopyTimeout = null) where T : class
|
||||
async public static Task ExecuteSqlBulkCopyAsync<T>(this IInsert<T> that, SqlBulkCopyOptions copyOptions = SqlBulkCopyOptions.Default, int? batchSize = null, int? bulkCopyTimeout = null, CancellationToken cancellationToken = default) where T : class
|
||||
{
|
||||
var insert = that as FreeSql.SqlServer.Curd.SqlServerInsert<T>;
|
||||
if (insert == null) throw new Exception("ExecuteSqlBulkCopyAsync 是 FreeSql.Provider.SqlServer 特有的功能");
|
||||
@ -161,7 +162,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
bulkCopy.DestinationTableName = dt.TableName;
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
bulkCopy.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);
|
||||
return bulkCopy.WriteToServerAsync(dt);
|
||||
return bulkCopy.WriteToServerAsync(dt, cancellationToken);
|
||||
};
|
||||
|
||||
try
|
||||
@ -194,7 +195,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
if (conn.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
isNotOpen = true;
|
||||
await conn.OpenAsync();
|
||||
await conn.OpenAsync(cancellationToken);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user