diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index c21ae6656..25f23c323 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -6376,126 +6376,3 @@ - - - - - 插入数据,传入实体集合 - - - - - - - - 插入数据,传入实体集合 - - - - - - - - 插入或更新数据,此功能依赖数据库特性(低版本可能不支持),参考如下: - MySql 5.6+: on duplicate key update - PostgreSQL 9.4+: on conflict do update - SqlServer 2008+: merge into - Oracle 11+: merge into - Sqlite: replace into - DuckDB: on conflict do update - 达梦: merge into - 人大金仓:on conflict do update - 神通:merge into - MsAccess:不支持 - 注意区别:FreeSql.Repository 仓储也有 InsertOrUpdate 方法(不依赖数据库特性) - - - - - - - 修改数据 - - - - - - - 修改数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} - - - 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 - - - - - 查询数据 - - - - - - - 查询数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} - - - 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 - - - - - 删除数据 - - - - - - - 删除数据,传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} - - - 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 - - - - - 开启事务(不支持异步) - v1.5.0 关闭了线程事务超时自动提交的机制 - - 事务体 () => {} - - - - 开启事务(不支持异步) - v1.5.0 关闭了线程事务超时自动提交的机制 - - - 事务体 () => {} - - - - 数据库访问对象 - - - - - 所有拦截方法都在这里 - - - - - CodeFirst 模式开发相关方法 - - - - - DbFirst 模式开发相关方法 - - - - - 全局过滤设置,可默认附加为 Select/Update/Delete 条件 - - - - diff --git a/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs b/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs index 0601093ee..a9c1214ba 100644 --- a/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs +++ b/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs @@ -1,4 +1,5 @@ -using FreeSql.Internal.Model; + +using FreeSql.Internal.Model; using System; using System.Collections.Generic; using System.Data; @@ -10,6 +11,12 @@ namespace FreeSql { + + + + + + public interface ISelect : ISelect0, T1> where T2 : class { @@ -20,6 +27,7 @@ public interface ISelect : ISelect0, T1> where T2 : clas Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -37,6 +45,7 @@ public interface ISelect : ISelect0, T1> where T2 : clas Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -139,6 +148,7 @@ public interface ISelect : ISelect0, T1> where T Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -156,6 +166,7 @@ public interface ISelect : ISelect0, T1> where T Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -258,6 +269,7 @@ public interface ISelect : ISelect0, T1> Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -275,6 +287,7 @@ public interface ISelect : ISelect0, T1> Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -377,6 +390,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -394,6 +408,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -496,6 +511,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -513,6 +529,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -615,6 +632,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -632,6 +650,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -734,6 +753,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -751,6 +771,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -853,6 +874,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -870,6 +892,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -972,6 +995,7 @@ public interface ISelect : ISelect0 ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -989,6 +1013,7 @@ public interface ISelect : ISelect0 InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1091,6 +1116,7 @@ public interface ISelect : ISelect Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1108,6 +1134,7 @@ public interface ISelect : ISelect Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1210,6 +1237,7 @@ public interface ISelect : IS Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1227,6 +1255,7 @@ public interface ISelect : IS Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1329,6 +1358,7 @@ public interface ISelect Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1346,6 +1376,7 @@ public interface ISelect Task InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1448,6 +1479,7 @@ public interface ISelect ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1465,6 +1497,7 @@ public interface ISelect InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1567,6 +1600,7 @@ public interface ISelect ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1584,6 +1618,7 @@ public interface ISelect InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1686,6 +1721,7 @@ public interface ISelect ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -1703,6 +1739,7 @@ public interface ISelect InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -1791,4 +1828,6 @@ public interface ISelect> ToListPrivateAsync(GetAllFieldExpressionTreeInfo af, Rea if (SameSelectPending(ref sql, csspsod)) return Task.FromResult(new List()); return ToListAfPrivateAsync(sql, af, otherData, cancellationToken); } + #region ToChunkAsync + async internal Task ToListAfChunkPrivateAsync(int chunkSize, Func>, Task> chunkDone, string sql, GetAllFieldExpressionTreeInfo af, ReadAnonymousTypeOtherInfo[] otherData, CancellationToken cancellationToken) + { + if (_cancel?.Invoke() == true) return; + var dbParms = _params.ToArray(); + var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, _tables[0].Table, Aop.CurdType.Select, sql, dbParms); + _orm.Aop.CurdBeforeHandler?.Invoke(this, before); + var ret = new FetchCallbackArgs> { Object = new List() }; + var retCount = 0; + Exception exception = null; + var checkDoneTimes = 0; + try + { + await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, async fetch => + { + if (cancellationToken.IsCancellationRequested) + { + fetch.IsBreak = true; + return; + } + ret.Object.Add(af.Read(_orm, fetch.Object)); + if (otherData != null) + { + var idx = af.FieldCount - 1; + foreach (var other in otherData) + other.retlist.Add(_commonExpression.ReadAnonymous(other.read, fetch.Object, ref idx, false, null, ret.Object.Count - 1, null, null)); + } + retCount++; + if (chunkSize > 0 && chunkSize == ret.Object.Count) + { + checkDoneTimes++; + + foreach (var include in _includeToListAsync) await include?.Invoke(ret.Object, cancellationToken); + _trackToList?.Invoke(ret.Object); + await chunkDone(ret); + fetch.IsBreak = ret.IsBreak; + + ret.Object.Clear(); + if (otherData != null) + foreach (var other in otherData) + other.retlist.Clear(); + } + }, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken); + } + catch (Exception ex) + { + exception = ex; + throw; + } + finally + { + var after = new Aop.CurdAfterEventArgs(before, exception, retCount); + _orm.Aop.CurdAfterHandler?.Invoke(this, after); + } + if (ret.Object.Any() || checkDoneTimes == 0) + { + foreach (var include in _includeToListAsync) await include?.Invoke(ret.Object, cancellationToken); + _trackToList?.Invoke(ret.Object); + await chunkDone(ret); + } + } + internal Task ToListChunkPrivateAsync(int chunkSize, Func>, Task> chunkDone, GetAllFieldExpressionTreeInfo af, ReadAnonymousTypeOtherInfo[] otherData, CancellationToken cancellationToken) + { + string sql = null; + if (otherData?.Length > 0) + { + var sbField = new StringBuilder().Append(af.Field); + foreach (var other in otherData) + sbField.Append(other.field); + sql = this.ToSql(sbField.ToString().TrimStart(',')); + } + else + sql = this.ToSql(af.Field); + + return ToListAfChunkPrivateAsync(chunkSize, chunkDone, sql, af, otherData, cancellationToken); + } + public Task ToChunkAsync(int size, Func>, Task> done, bool includeNestedMembers = false, CancellationToken cancellationToken = default) + { + if (_selectExpression != null) throw new ArgumentException(CoreErrorStrings.Before_Chunk_Cannot_Use_Select); + return this.ToListChunkPrivateAsync(size, done, includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null, cancellationToken); + } + + async internal Task ToListMrChunkPrivateAsync(int chunkSize, Func>, Task> chunkDone, string sql, ReadAnonymousTypeAfInfo af, CancellationToken cancellationToken) + { + if (_cancel?.Invoke() == true) return; + var type = typeof(TReturn); + var dbParms = _params.ToArray(); + var before = new Aop.CurdBeforeEventArgs(_tables[0].Table.Type, _tables[0].Table, Aop.CurdType.Select, sql, dbParms); + _orm.Aop.CurdBeforeHandler?.Invoke(this, before); + var ret = new FetchCallbackArgs> { Object = new List() }; + var retCount = 0; + Exception exception = null; + var checkDoneTimes = 0; + try + { + await _orm.Ado.ExecuteReaderAsync(_connection, _transaction, async fetch => + { + if (cancellationToken.IsCancellationRequested) + { + fetch.IsBreak = true; + return; + } + var index = -1; + ret.Object.Add((TReturn)_commonExpression.ReadAnonymous(af.map, fetch.Object, ref index, false, null, ret.Object.Count, af.fillIncludeMany, af.fillSubSelectMany)); + retCount++; + if (chunkSize > 0 && chunkSize == ret.Object.Count) + { + checkDoneTimes++; + + foreach (var include in _includeToListAsync) await include?.Invoke(ret.Object, cancellationToken); + _trackToList?.Invoke(ret.Object); + await chunkDone(ret); + fetch.IsBreak = ret.IsBreak; + + ret.Object.Clear(); + } + }, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken); + } + catch (Exception ex) + { + exception = ex; + throw; + } + finally + { + var after = new Aop.CurdAfterEventArgs(before, exception, retCount); + _orm.Aop.CurdAfterHandler?.Invoke(this, after); + } + if (ret.Object.Any() || checkDoneTimes == 0) + { + foreach (var include in _includeToListAsync) await include?.Invoke(ret.Object, cancellationToken); + _trackToList?.Invoke(ret.Object); + await chunkDone(ret); + } + } + public Task InternalToChunkAsync(Expression select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var af = this.GetExpressionField(select); + var sql = this.ToSql(af.field); + return this.ToListMrChunkPrivateAsync(size, done, sql, af, cancellationToken); + } + #endregion public Task> ToDictionaryAsync(Func keySelector, CancellationToken cancellationToken) => ToDictionaryAsync(keySelector, a => a, cancellationToken); async public Task> ToDictionaryAsync(Func keySelector, Func elementSelector, CancellationToken cancellationToken) diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs index 79023f780..69e6678e5 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs @@ -390,6 +390,13 @@ Task> ISelect.ToListAsync(Expression> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -453,6 +460,12 @@ Task> ISelect.ToListAsync(Expression).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -866,6 +879,13 @@ Task> ISelect.ToListAsync(Expression> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -929,6 +949,12 @@ Task> ISelect.ToListAsync(Expression).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -1345,6 +1371,13 @@ Task> ISelect.ToListAsync(Expression> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -1408,6 +1441,12 @@ Task> ISelect.ToListAsync(Expression).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -1827,6 +1866,13 @@ Task> ISelect.ToListAsync(Expression< } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -1890,6 +1936,12 @@ Task> ISelect.ToListAsync(Expression< return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -2312,6 +2364,13 @@ Task> ISelect.ToListAsync(Express } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -2375,6 +2434,12 @@ Task> ISelect.ToListAsync(Express return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -2800,6 +2865,13 @@ Task> ISelect.ToListAsync(Exp } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -2863,6 +2935,12 @@ Task> ISelect.ToListAsync(Exp return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -3291,6 +3369,13 @@ Task> ISelect.ToListAsync } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -3354,6 +3439,12 @@ Task> ISelect.ToListAsync return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -3785,6 +3876,13 @@ Task> ISelect.ToListAsync> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -3848,6 +3946,12 @@ Task> ISelect.ToListAsync).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -4282,6 +4386,13 @@ Task> ISelect.ToListAsync } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -4345,6 +4456,12 @@ Task> ISelect.ToListAsync return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -4782,6 +4899,13 @@ Task> ISelect.ToList } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -4845,6 +4969,12 @@ Task> ISelect.ToList return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -5285,6 +5415,13 @@ Task> ISelect.T } Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -5348,6 +5485,12 @@ Task> ISelect.T return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -5791,6 +5934,13 @@ Task> ISelect> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -5854,6 +6004,12 @@ Task> ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -6300,6 +6456,13 @@ Task> ISelect> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -6363,6 +6526,12 @@ Task> ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -6812,6 +6981,13 @@ Task> ISelect> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -6875,6 +7051,12 @@ Task> ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -7327,6 +7509,13 @@ Task> ISelect> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -7390,6 +7579,12 @@ Task> ISelect).ToListAsync((Expression>)expModify, cancellationToken); } + Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); + } + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); @@ -7421,3 +7616,5 @@ async Task ISelect> : ISelect0>, T1> <#= Task ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default); @@ -73,6 +74,7 @@ public interface ISelect<<#=NewStr #>> : ISelect0>, T1> <#= Task InsertIntoAsync(string tableName, Expression>, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression>, TReturn>> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression>, TReturn>> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression>, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken = default); Task ToOneAsync(Expression>, TReturn>> select, CancellationToken cancellationToken = default); Task FirstAsync(Expression>, TReturn>> select, CancellationToken cancellationToken = default); diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt index 962a8c40d..df9b6a38c 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt +++ b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt @@ -439,6 +439,13 @@ namespace FreeSql.Internal.CommonProvider } Task> ISelect<<#=NewStr #>>.ToListAsync(CancellationToken cancellationToken) => (this as ISelect<<#=NewStr #>>).ToListAsync(GetToListDtoSelector(), cancellationToken); + async Task ISelect<<#=NewStr #>>.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + if (select == null || done == null) return; + for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } + Task ISelect<<#=NewStr #>>.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); @@ -501,6 +508,12 @@ namespace FreeSql.Internal.CommonProvider var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); return (this as ISelect<<#=NewStr #>>).ToListAsync((Expression, TReturn>>)expModify, cancellationToken); } + + Task ISelect<<#=NewStr #>>.ToChunkAsync(Expression>, TReturn>> select, int size, Func>, Task> done, CancellationToken cancellationToken) + { + var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); + return (this as ISelect<<#=NewStr #>>).ToChunkAsync((Expression, TReturn>>)expModify, size, done, cancellationToken); + } Task ISelect<<#=NewStr #>>.ToDataTableAsync(Expression>, TReturn>> select, CancellationToken cancellationToken) {