diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs index a528cfdf5..67331cbb5 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs @@ -14,6 +14,7 @@ namespace MongoDb.Ado.data { public class DbDataReaderFactoryAsync { + public CancellationToken token { get; set; } public readonly static Dictionary Items = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "find", new QueryFindHandlerAsync() }, @@ -28,7 +29,8 @@ namespace MongoDb.Ado.data { await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection, cancellationToken); return new DataTable().CreateDataReader(); - } + } + handler.token = cancellationToken; return await handler.HandlerAsync(collection, doc); } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/IQueryHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/IQueryHandlerAsync.cs index 0c9420716..1af9a283d 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/IQueryHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/IQueryHandlerAsync.cs @@ -1,12 +1,15 @@ using MongoDB.Bson; using MongoDB.Driver; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public interface IQueryHandlerAsync { + CancellationToken token { get; set; } + Task HandlerAsync(IMongoCollection collection, BsonValue doc); } } \ No newline at end of file diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryAggregateHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryAggregateHandlerAsync.cs index 44e97346d..918a2a4e5 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryAggregateHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryAggregateHandlerAsync.cs @@ -6,12 +6,14 @@ using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class QueryAggregateHandlerAsync : IQueryHandlerAsync { + public CancellationToken token { get; set; } public async Task HandlerAsync(IMongoCollection collection, BsonValue doc) { // 解析 JSON 字符串为 BsonArray @@ -21,7 +23,7 @@ namespace MongoDb.Ado.data var aggregateFluent = collection.Aggregate(pipeline.Select(stage => new BsonDocument(stage.AsBsonDocument)).ToArray()); // 执行聚合查询并返回 DbDataReader - var cursor =await aggregateFluent.ToListAsync(); + var cursor =await aggregateFluent.ToListAsync(token); return new MongoDbBsonDocumentDataReader(cursor); } } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryFindHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryFindHandlerAsync.cs index ef5f76141..c24ab7097 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryFindHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/QueryFindHandlerAsync.cs @@ -5,12 +5,14 @@ using System.Collections; using System.Collections.Generic; using System.Data.Common; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class QueryFindHandlerAsync : IQueryHandlerAsync { + public CancellationToken token { get; set; } public async Task HandlerAsync(IMongoCollection collection, BsonValue doc) { BsonDocument filter; @@ -37,7 +39,7 @@ namespace MongoDb.Ado.data if (projection != null) findFluent = findFluent.Project(projection); - var cursor =await findFluent.ToListAsync(); + var cursor =await findFluent.ToListAsync(token); return new MongoDbBsonDocumentDataReader(cursor); // 你要确保这个类支持逐行读取 BsonDocument } }