diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 80a91885b..9cdfa2b17 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -621,6 +621,17 @@ namespace base_entity BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + Task.Run(async () => + { + await foreach (var xxs1 in fsql.Select().ToChunkAsyncEnumerable(10)) + { + foreach (var item in xxs1) + { + Console.WriteLine(item.Nickname); + } + } + }).Wait(); + Utils.IsStrict = false; var user1Tb = fsql.CodeFirst.GetTableByEntity(typeof(User11)); diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj index 79f2ab7ef..42340e9db 100644 --- a/FreeSql/FreeSql.csproj +++ b/FreeSql/FreeSql.csproj @@ -34,6 +34,19 @@ + + + ISelect2`16.tt + True + True + + + Select1Provider2`16.tt + True + True + + + TextTemplatingFileGenerator @@ -57,6 +70,9 @@ net45 + + ns21 + diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 3a9fdc72b..e77e3a1f5 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -2219,13 +2219,12 @@ false: 返回 2级 LeftJoin/InnerJoin/RightJoin 对象;true: 返回所有 LeftJoin/InnerJoin/RightJoin 的导航数据 - + 执行SQL查询,分块返回数据,可减少内存开销。比如读取10万条数据,每次返回100条处理。 数据块的大小 处理数据块 - false: 返回 2级 LeftJoin/InnerJoin/RightJoin 对象;true: 返回所有 LeftJoin/InnerJoin/RightJoin 的导航数据 diff --git a/FreeSql/Interface/Curd/ISelect/ISelect0.cs b/FreeSql/Interface/Curd/ISelect/ISelect0.cs index 989cd1885..61fa4b1a5 100644 --- a/FreeSql/Interface/Curd/ISelect/ISelect0.cs +++ b/FreeSql/Interface/Curd/ISelect/ISelect0.cs @@ -31,6 +31,9 @@ namespace FreeSql Task AnyAsync(CancellationToken cancellationToken = default); Task CountAsync(CancellationToken cancellationToken = default); #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(int size); +#endif /// /// 控制取消本次查询 @@ -117,8 +120,7 @@ namespace FreeSql /// /// 数据块的大小 /// 处理数据块 - /// false: 返回 2级 LeftJoin/InnerJoin/RightJoin 对象;true: 返回所有 LeftJoin/InnerJoin/RightJoin 的导航数据 - void ToChunk(int size, Action>> done, bool includeNestedMembers = false); + void ToChunk(int size, Action>> done); /// /// 执行SQL查询,返回 field 指定字段的记录,并以元组或基础类型(int,string,long)接收,记录不存在时返回 Count 为 0 的列表 /// diff --git a/FreeSql/Interface/Curd/ISelect/ISelect1.cs b/FreeSql/Interface/Curd/ISelect/ISelect1.cs index c0eed733e..257bf31c3 100644 --- a/FreeSql/Interface/Curd/ISelect/ISelect1.cs +++ b/FreeSql/Interface/Curd/ISelect/ISelect1.cs @@ -18,8 +18,9 @@ namespace FreeSql Task InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken = default) where TTargetEntity : class; Task ToDataTableAsync(Expression> select, CancellationToken cancellationToken = default); Task> ToListAsync(Expression> select, CancellationToken cancellationToken = default); + Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken); Task> ToListAsync(CancellationToken cancellationToken = default); - + Task ToOneAsync(Expression> select, CancellationToken cancellationToken = default); Task ToOneAsync(CancellationToken cancellationToken = default); Task FirstAsync(Expression> select, CancellationToken cancellationToken = default); @@ -31,6 +32,9 @@ namespace FreeSql Task MaxAsync(Expression> column, CancellationToken cancellationToken = default); Task AvgAsync(Expression> column, CancellationToken cancellationToken = default); #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif /// /// 执行SQL查询,是否有记录 diff --git a/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs b/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs index 10992fbfd..81b7e5ff8 100644 --- a/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs +++ b/FreeSql/Interface/Curd/ISelect/ISelect2`16.cs @@ -9,14 +9,6 @@ using System.Threading.Tasks; namespace FreeSql { - - - - - - - - public interface ISelect : ISelect0, T1> where T2 : class { @@ -59,6 +51,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -182,6 +178,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -305,6 +305,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -428,6 +432,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -551,6 +559,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -674,6 +686,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -797,6 +813,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -920,6 +940,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1043,6 +1067,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1166,6 +1194,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1289,6 +1321,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1412,6 +1448,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1535,6 +1575,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1658,6 +1702,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); @@ -1781,6 +1829,10 @@ namespace FreeSql #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size); +#endif + bool Any(Expression> exp); int InsertInto(string tableName, Expression> select) where TTargetEntity : class; DataTable ToDataTable(Expression> select); diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs index 80c862fda..d79f5faf6 100644 --- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs +++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs @@ -81,7 +81,7 @@ namespace FreeSql.Internal.CommonProvider }, cmdType, cmdText, cmdTimeout, cmdParms, cancellationToken); return ret; } -#region QueryAsync multi + #region QueryAsync multi public Task, List>> QueryAsync(string cmdText, object parms = null, CancellationToken cancellationToken = default) => QueryAsync(null, null, CommandType.Text, cmdText, 0, GetDbParamtersByObject(cmdText, parms), cancellationToken); public Task, List>> QueryAsync(DbTransaction transaction, string cmdText, object parms = null, CancellationToken cancellationToken = default) => QueryAsync(null, transaction, CommandType.Text, cmdText, 0, GetDbParamtersByObject(cmdText, parms), cancellationToken); public Task, List>> QueryAsync(DbConnection connection, DbTransaction transaction, string cmdText, object parms = null, CancellationToken cancellationToken = default) => QueryAsync(connection, transaction, CommandType.Text, cmdText, 0, GetDbParamtersByObject(cmdText, parms), cancellationToken); @@ -493,9 +493,22 @@ namespace FreeSql.Internal.CommonProvider public Task ExecuteReaderAsync(Func, Task> fetchHandler, CommandType cmdType, string cmdText, DbParameter[] cmdParms, CancellationToken cancellationToken = default) => ExecuteReaderAsync(null, null, fetchHandler, cmdType, cmdText, 0, cmdParms, cancellationToken); public Task ExecuteReaderAsync(DbTransaction transaction, Func, Task> fetchHandler, CommandType cmdType, string cmdText, DbParameter[] cmdParms, CancellationToken cancellationToken = default) => ExecuteReaderAsync(null, transaction, fetchHandler, cmdType, cmdText, 0, cmdParms, cancellationToken); public Task ExecuteReaderAsync(DbConnection connection, DbTransaction transaction, Func, Task> fetchHandler, CommandType cmdType, string cmdText, int cmdTimeout, DbParameter[] cmdParms, CancellationToken cancellationToken = default) => ExecuteReaderMultipleAsync(1, connection, transaction, (fetch, result) => fetchHandler(fetch), null, cmdType, cmdText, cmdTimeout, cmdParms, cancellationToken); - async public Task ExecuteReaderMultipleAsync(int multipleResult, DbConnection connection, DbTransaction transaction, Func, int, Task> fetchHandler, Action schemaHandler, CommandType cmdType, string cmdText, int cmdTimeout, DbParameter[] cmdParms, CancellationToken cancellationToken = default) + public Task ExecuteReaderMultipleAsync(int multipleResult, DbConnection connection, DbTransaction transaction, Func, int, Task> fetchHandler, Action schemaHandler, CommandType cmdType, string cmdText, int cmdTimeout, DbParameter[] cmdParms, CancellationToken cancellationToken = default) => ExecuteReaderMultipleAsync(multipleResult, connection, transaction, fetchHandler, schemaHandler, cmdType, cmdText, cmdTimeout, cmdParms, false, cancellationToken); + +#if ns21 + internal class DbDataReaderAsyncEnumerator { - if (string.IsNullOrEmpty(cmdText)) return; + public DbDataReader Reader; + public Func Dispose; + } + async internal Task +#else + async internal Task +#endif + ExecuteReaderMultipleAsync(int multipleResult, DbConnection connection, DbTransaction transaction, Func, int, Task> fetchHandler, Action schemaHandler, CommandType cmdType, string cmdText, int cmdTimeout, DbParameter[] cmdParms, + bool isAsyncEnumerator, CancellationToken cancellationToken = default) + { + if (string.IsNullOrEmpty(cmdText)) return null; var dt = DateTime.Now; var logtxt = new StringBuilder(); var logtxt_dt = DateTime.Now; @@ -542,7 +555,7 @@ namespace FreeSql.Internal.CommonProvider LoggerException(pool, pc, null, dt, logtxt); pc.cmd.Parameters.Clear(); if (DataType == DataType.Sqlite) pc.cmd.Dispose(); - return; + return null; } if (IsTracePerformance) @@ -577,8 +590,7 @@ namespace FreeSql.Internal.CommonProvider LoggerException(pool, pc, new Exception(CoreErrorStrings.Connection_Failed_Switch_Servers), dt, logtxt, false); pc.cmd.Parameters.Clear(); if (DataType == DataType.Sqlite) pc.cmd.Dispose(); - await ExecuteReaderMultipleAsync(multipleResult, connection, transaction, fetchHandler, schemaHandler, cmdType, cmdText, cmdTimeout, cmdParms, cancellationToken); - return; + return await ExecuteReaderMultipleAsync(multipleResult, connection, transaction, fetchHandler, schemaHandler, cmdType, cmdText, cmdTimeout, cmdParms, isAsyncEnumerator, cancellationToken); } } else @@ -591,6 +603,44 @@ namespace FreeSql.Internal.CommonProvider logtxt.Append("Pool.Get: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n"); logtxt_dt = DateTime.Now; } +#if ns21 + if (isAsyncEnumerator) + { + var dr = await pc.cmd.ExecuteReaderAsync(cancellationToken); + return new DbDataReaderAsyncEnumerator + { + Reader = dr, + Dispose = async (ex2) => + { + try + { + await dr.CloseAsync(); + await dr.DisposeAsync(); + } + catch (Exception ex3) + { + if (ex2 == null) ex2 = ex3; + } + if (IsTracePerformance) + { + logtxt.Append("ExecuteReader: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms\r\n"); + logtxt_dt = DateTime.Now; + } + ex = ex2; + + if (conn != null) + { + if (IsTracePerformance) logtxt_dt = DateTime.Now; + ReturnConnection(pool, conn, ex); //pool.Return(conn, ex); + if (IsTracePerformance) logtxt.Append("Pool.Return: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms"); + } + LoggerException(pool, pc, ex, dt, logtxt); + pc.cmd.Parameters.Clear(); + if (DataType == DataType.Sqlite) pc.cmd.Dispose(); + } + }; + } +#endif using (var dr = await pc.cmd.ExecuteReaderAsync(cancellationToken)) { int resultIndex = 0; @@ -642,6 +692,7 @@ namespace FreeSql.Internal.CommonProvider LoggerException(pool, pc, ex, dt, logtxt); pc.cmd.Parameters.Clear(); if (DataType == DataType.Sqlite) pc.cmd.Dispose(); + return null; } public Task ExecuteArrayAsync(string cmdText, object parms = null, CancellationToken cancellationToken = default) => ExecuteArrayAsync(null, null, CommandType.Text, cmdText, 0, GetDbParamtersByObject(cmdText, parms), cancellationToken); public Task ExecuteArrayAsync(DbTransaction transaction, string cmdText, object parms = null, CancellationToken cancellationToken = default) => ExecuteArrayAsync(null, transaction, CommandType.Text, cmdText, 0, GetDbParamtersByObject(cmdText, parms), cancellationToken); diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select0ProviderReader.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select0ProviderReader.cs index 40befd1e5..b3a226fb3 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select0ProviderReader.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select0ProviderReader.cs @@ -3,17 +3,15 @@ using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Data; using System.Data.Common; -using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using static FreeSql.Internal.CommonProvider.AdoProvider; namespace FreeSql.Internal.CommonProvider { @@ -234,10 +232,10 @@ namespace FreeSql.Internal.CommonProvider ToListAfChunkPrivate(chunkSize, chunkDone, sql, af, otherData); } - public void ToChunk(int size, Action>> done, bool includeNestedMembers = false) + public void ToChunk(int size, Action>> done) { if (_selectExpression != null) throw new ArgumentException(CoreErrorStrings.Before_Chunk_Cannot_Use_Select); - this.ToListChunkPrivate(size, done, includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null); + this.ToListChunkPrivate(size, done, this.GetAllFieldExpressionTreeLevel2(), null); } internal void ToListMrChunkPrivate(int chunkSize, Action>> chunkDone, string sql, ReadAnonymousTypeAfInfo af) @@ -1262,87 +1260,6 @@ namespace FreeSql.Internal.CommonProvider 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; @@ -1743,6 +1660,192 @@ namespace FreeSql.Internal.CommonProvider } } #endif + +#if ns21 + #region ToChunkAsyncEnumerable + class LocalAsyncEnumerable : IAsyncEnumerable> + { + internal Func>> _GetAsyncEnumerator; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => _GetAsyncEnumerator(cancellationToken); + } + class LocalAsyncEnumerator : IAsyncEnumerator> + { + internal Func> _Current; + internal Func> _MoveNextAsync; + internal Func _DisposeAsync; + + public List Current => _Current(); + public ValueTask MoveNextAsync() => _MoveNextAsync(); + public ValueTask DisposeAsync() => _DisposeAsync(); + } + + internal IAsyncEnumerator> ToListAfChunkPrivateAsyncEnumerable(int chunkSize, string sql, GetAllFieldExpressionTreeInfo af, ReadAnonymousTypeOtherInfo[] otherData, CancellationToken cancellationToken) + { + if (_cancel?.Invoke() == true) return new LocalAsyncEnumerator + { + _Current = () => null, + _MoveNextAsync = () => new ValueTask(false), + _DisposeAsync = () => new ValueTask() + }; + Exception exception = null; + var retCount = 0; + DbDataReaderAsyncEnumerator dataReaderAsyncEnumerator = null; + List items = null; + async ValueTask LocalMoveNextAsync() + { + try + { + if (dataReaderAsyncEnumerator == null) + { + 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); + dataReaderAsyncEnumerator = await (_orm.Ado as AdoProvider).ExecuteReaderMultipleAsync(1, _connection, _transaction, null, null, CommandType.Text, sql, _commandTimeout, dbParms, true, cancellationToken); + if (dataReaderAsyncEnumerator == null) return false; + } + if (!await dataReaderAsyncEnumerator.Reader.ReadAsync(cancellationToken)) + { + items = null; + return false; + } + items = null; + for (var a = 0; a < chunkSize; a++) + { + if (!await dataReaderAsyncEnumerator.Reader.ReadAsync(cancellationToken)) + { + if (a == 0) return false; + break; + } + if (a == 0) items = new List(); + items.Add(af.Read(_orm, dataReaderAsyncEnumerator.Reader)); + if (otherData != null) + { + var idx = af.FieldCount - 1; + foreach (var other in otherData) + other.retlist.Add(_commonExpression.ReadAnonymous(other.read, dataReaderAsyncEnumerator.Reader, ref idx, false, null, items.Count - 1, null, null)); + } + retCount++; + } + foreach (var include in _includeToListAsync) await include?.Invoke(items, cancellationToken); + _trackToList?.Invoke(items); + return true; + } + catch (Exception ex) + { + exception = ex; + return false; + } + } + async ValueTask LocalDisposeAsync() + { + items?.Clear(); + await dataReaderAsyncEnumerator.Dispose(exception); + dataReaderAsyncEnumerator = null; + } + return new LocalAsyncEnumerator + { + _Current = () => items, + _MoveNextAsync = LocalMoveNextAsync, + _DisposeAsync = LocalDisposeAsync + }; + } + internal IAsyncEnumerable> ToListChunkPrivateAsyncEnumerable(int chunkSize, GetAllFieldExpressionTreeInfo af, ReadAnonymousTypeOtherInfo[] otherData) + { + 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 new LocalAsyncEnumerable + { + _GetAsyncEnumerator = (cancellationToken) => this.ToListAfChunkPrivateAsyncEnumerable(chunkSize, sql, af, otherData, cancellationToken) + }; + } + public IAsyncEnumerable> ToChunkAsyncEnumerable(int size) + { + if (_selectExpression != null) throw new ArgumentException(CoreErrorStrings.Before_Chunk_Cannot_Use_Select); + return this.ToListChunkPrivateAsyncEnumerable(size, this.GetAllFieldExpressionTreeLevel2(), null); + } + + + internal IAsyncEnumerator> ToListMrChunkPrivateAsyncEnumerable(int chunkSize, string sql, ReadAnonymousTypeAfInfo af, CancellationToken cancellationToken) + { + if (_cancel?.Invoke() == true) return new LocalAsyncEnumerator + { + _Current = () => null, + _MoveNextAsync = () => new ValueTask(false), + _DisposeAsync = () => new ValueTask() + }; + Exception exception = null; + var retCount = 0; + DbDataReaderAsyncEnumerator dataReaderAsyncEnumerator = null; + List items = null; + async ValueTask LocalMoveNextAsync() + { + try + { + if (dataReaderAsyncEnumerator == null) + { + 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); + dataReaderAsyncEnumerator = await (_orm.Ado as AdoProvider).ExecuteReaderMultipleAsync(1, _connection, _transaction, null, null, CommandType.Text, sql, _commandTimeout, dbParms, true, cancellationToken); + if (dataReaderAsyncEnumerator == null) return false; + } + items = null; + for (var a = 0; a < chunkSize; a++) + { + if (!await dataReaderAsyncEnumerator.Reader.ReadAsync(cancellationToken)) + { + if (a == 0) return false; + break; + } + if (a == 0) items = new List(); + var index = -1; + items.Add((TReturn)_commonExpression.ReadAnonymous(af.map, dataReaderAsyncEnumerator.Reader, ref index, false, null, items.Count, af.fillIncludeMany, af.fillSubSelectMany)); + retCount++; + } + foreach (var include in _includeToListAsync) await include?.Invoke(items, cancellationToken); + _trackToList?.Invoke(items); + return true; + } + catch (Exception ex) + { + exception = ex; + return false; + } + } + async ValueTask LocalDisposeAsync() + { + items?.Clear(); + await dataReaderAsyncEnumerator.Dispose(exception); + dataReaderAsyncEnumerator = null; + } + return new LocalAsyncEnumerator + { + _Current = () => items, + _MoveNextAsync = LocalMoveNextAsync, + _DisposeAsync = LocalDisposeAsync + }; + } + public IAsyncEnumerable> InternalToChunkAsyncEnumerable(Expression select, int chunkSize) + { + var af = this.GetExpressionField(select); + var sql = this.ToSql(af.field); + return new LocalAsyncEnumerable + { + _GetAsyncEnumerator = (cancellationToken) => this.ToListMrChunkPrivateAsyncEnumerable(chunkSize, sql, af, cancellationToken) + }; + } + #endregion +#endif #endregion } } diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs index 5ee1b7e8c..0ba8f43c5 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs @@ -1810,6 +1810,12 @@ namespace FreeSql.Internal.CommonProvider _tables[0].Parameter = select.Parameters[0]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } + async public Task ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken cancellationToken = default) + { + if (select == null || done == null) return; + _tables[0].Parameter = select.Parameters[0]; + await this.InternalToChunkAsync(select.Body, size, done, cancellationToken); + } public Task ToAggregateAsync(Expression, TReturn>> select, CancellationToken cancellationToken = default) { if (select == null) return Task.FromResult(default(TReturn)); @@ -1830,5 +1836,13 @@ namespace FreeSql.Internal.CommonProvider public Task FirstAsync(CancellationToken cancellationToken = default) => this.ToOneAsync(cancellationToken); public override Task> ToListAsync(bool includeNestedMembers, CancellationToken cancellationToken = default) => base.ToListAsync(_isIncluded || includeNestedMembers, cancellationToken); #endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + if (select != null) _tables[0].Parameter = select.Parameters[0]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } +#endif } } \ No newline at end of file diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs index 0cdbb552c..188dc693d 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider2`16.cs @@ -11,8 +11,8 @@ using System.Threading.Tasks; namespace FreeSql.Internal.CommonProvider { - public abstract class Select2Provider : Select0Provider, T1>, ISelect - where T2 : class + public abstract class Select2Provider : Select0Provider, T1>, ISelect + where T2 : class { public Select2Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) @@ -22,12 +22,12 @@ namespace FreeSql.Internal.CommonProvider } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; return old; }); @@ -35,174 +35,174 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2) + ISelect ISelect.As(string aliasT1,string aliasT2) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -212,219 +212,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -434,101 +428,105 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select3Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class + + public abstract class Select3Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class { public Select3Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; return old; }); @@ -536,7 +534,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -544,167 +542,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -714,219 +712,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -936,103 +928,107 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select4Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class + + public abstract class Select4Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class { public Select4Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; return old; }); @@ -1040,7 +1036,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -1049,167 +1045,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -1219,219 +1215,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -1441,105 +1431,109 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select5Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class + + public abstract class Select5Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class { public Select5Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; return old; }); @@ -1547,7 +1541,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -1557,167 +1551,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -1727,219 +1721,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -1949,107 +1937,111 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select6Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class + + public abstract class Select6Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class { public Select6Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; return old; }); @@ -2057,7 +2049,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -2068,167 +2060,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -2238,219 +2230,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -2460,109 +2446,113 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select7Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class + + public abstract class Select7Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class { public Select7Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; return old; }); @@ -2570,7 +2560,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -2582,167 +2572,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -2752,219 +2742,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -2974,111 +2958,115 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select8Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class + + public abstract class Select8Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class { public Select8Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; return old; }); @@ -3086,7 +3074,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -3099,167 +3087,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -3269,219 +3257,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -3491,113 +3473,117 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select9Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class + + public abstract class Select9Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class { public Select9Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; return old; }); @@ -3605,7 +3591,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -3619,167 +3605,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -3789,219 +3775,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -4011,115 +3991,119 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select10Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class + + public abstract class Select10Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class { public Select10Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; return old; }); @@ -4127,7 +4111,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -4142,167 +4126,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -4312,219 +4296,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -4534,117 +4512,121 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select11Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class + + public abstract class Select11Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class { public Select11Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; return old; }); @@ -4652,7 +4634,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -4668,167 +4650,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -4838,219 +4820,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -5060,119 +5036,123 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select12Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class + + public abstract class Select12Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class { public Select12Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11),typeof(T12)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, string sqlT12, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11,string sqlT12, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; - if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; return old; }); @@ -5180,7 +5160,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11, string aliasT12) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11,string aliasT12) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -5197,167 +5177,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k"), Expression.Parameter(typeof(T12), "l")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k"),Expression.Parameter(typeof(T12), "l")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -5367,219 +5347,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -5589,121 +5563,125 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select13Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class + + public abstract class Select13Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class { public Select13Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11),typeof(T12),typeof(T13)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, string sqlT12, string sqlT13, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11,string sqlT12,string sqlT13, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; - if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; - if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; +if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; return old; }); @@ -5711,7 +5689,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11, string aliasT12, string aliasT13) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11,string aliasT12,string aliasT13) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -5729,167 +5707,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k"), Expression.Parameter(typeof(T12), "l"), Expression.Parameter(typeof(T13), "m")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k"),Expression.Parameter(typeof(T12), "l"),Expression.Parameter(typeof(T13), "m")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -5899,219 +5877,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -6121,123 +6093,127 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select14Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class + + public abstract class Select14Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class { public Select14Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11),typeof(T12),typeof(T13),typeof(T14)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, string sqlT12, string sqlT13, string sqlT14, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11,string sqlT12,string sqlT13,string sqlT14, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; - if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; - if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; - if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; +if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; +if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; return old; }); @@ -6245,7 +6221,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11, string aliasT12, string aliasT13, string aliasT14) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11,string aliasT12,string aliasT13,string aliasT14) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -6264,167 +6240,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k"), Expression.Parameter(typeof(T12), "l"), Expression.Parameter(typeof(T13), "m"), Expression.Parameter(typeof(T14), "n")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k"),Expression.Parameter(typeof(T12), "l"),Expression.Parameter(typeof(T13), "m"),Expression.Parameter(typeof(T14), "n")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -6434,219 +6410,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -6656,125 +6626,129 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select15Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class + + public abstract class Select15Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class { public Select15Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14), typeof(T15)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11),typeof(T12),typeof(T13),typeof(T14),typeof(T15)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T15)), Alias = $"SP10o", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T15)), Alias = $"SP10o", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, string sqlT12, string sqlT13, string sqlT14, string sqlT15, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11,string sqlT12,string sqlT13,string sqlT14,string sqlT15, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; - if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; - if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; - if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; - if (type == _tables[14].Table?.Type && string.IsNullOrEmpty(sqlT15) == false) return $"({sqlT15})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; +if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; +if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; +if (type == _tables[14].Table?.Type && string.IsNullOrEmpty(sqlT15) == false) return $"({sqlT15})"; return old; }); @@ -6782,7 +6756,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11, string aliasT12, string aliasT13, string aliasT14, string aliasT15) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11,string aliasT12,string aliasT13,string aliasT14,string aliasT15) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -6802,167 +6776,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k"), Expression.Parameter(typeof(T12), "l"), Expression.Parameter(typeof(T13), "m"), Expression.Parameter(typeof(T14), "n"), Expression.Parameter(typeof(T15), "o")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k"),Expression.Parameter(typeof(T12), "l"),Expression.Parameter(typeof(T13), "m"),Expression.Parameter(typeof(T14), "n"),Expression.Parameter(typeof(T15), "o")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -6972,219 +6946,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -7194,127 +7162,131 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } - - public abstract class Select16Provider : Select0Provider, T1>, ISelect - where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class where T16 : class + + public abstract class Select16Provider : Select0Provider, T1>, ISelect + where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class where T16 : class { public Select16Provider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { - if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14), typeof(T15), typeof(T16)); + if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8),typeof(T9),typeof(T10),typeof(T11),typeof(T12),typeof(T13),typeof(T14),typeof(T15),typeof(T16)); _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T2)), Alias = $"SP10b", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T15)), Alias = $"SP10o", On = null, Type = SelectTableInfoType.From }); - _tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T16)), Alias = $"SP10p", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T3)), Alias = $"SP10c", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T4)), Alias = $"SP10d", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T5)), Alias = $"SP10e", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T6)), Alias = $"SP10f", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T7)), Alias = $"SP10g", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T8)), Alias = $"SP10h", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T9)), Alias = $"SP10i", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T10)), Alias = $"SP10j", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T11)), Alias = $"SP10k", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T12)), Alias = $"SP10l", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T13)), Alias = $"SP10m", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T14)), Alias = $"SP10n", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T15)), Alias = $"SP10o", On = null, Type = SelectTableInfoType.From }); +_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T16)), Alias = $"SP10p", On = null, Type = SelectTableInfoType.From }); } - ISelect ISelect.WithSql(string sqlT1, string sqlT2, string sqlT3, string sqlT4, string sqlT5, string sqlT6, string sqlT7, string sqlT8, string sqlT9, string sqlT10, string sqlT11, string sqlT12, string sqlT13, string sqlT14, string sqlT15, string sqlT16, object parms) + ISelect ISelect.WithSql(string sqlT1,string sqlT2,string sqlT3,string sqlT4,string sqlT5,string sqlT6,string sqlT7,string sqlT8,string sqlT9,string sqlT10,string sqlT11,string sqlT12,string sqlT13,string sqlT14,string sqlT15,string sqlT16, object parms) { this.AsTable((type, old) => { if (type == _tables[0].Table?.Type && string.IsNullOrEmpty(sqlT1) == false) return $"({sqlT1})"; - if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; - if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; - if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; - if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; - if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; - if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; - if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; - if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; - if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; - if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; - if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; - if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; - if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; - if (type == _tables[14].Table?.Type && string.IsNullOrEmpty(sqlT15) == false) return $"({sqlT15})"; - if (type == _tables[15].Table?.Type && string.IsNullOrEmpty(sqlT16) == false) return $"({sqlT16})"; +if (type == _tables[1].Table?.Type && string.IsNullOrEmpty(sqlT2) == false) return $"({sqlT2})"; +if (type == _tables[2].Table?.Type && string.IsNullOrEmpty(sqlT3) == false) return $"({sqlT3})"; +if (type == _tables[3].Table?.Type && string.IsNullOrEmpty(sqlT4) == false) return $"({sqlT4})"; +if (type == _tables[4].Table?.Type && string.IsNullOrEmpty(sqlT5) == false) return $"({sqlT5})"; +if (type == _tables[5].Table?.Type && string.IsNullOrEmpty(sqlT6) == false) return $"({sqlT6})"; +if (type == _tables[6].Table?.Type && string.IsNullOrEmpty(sqlT7) == false) return $"({sqlT7})"; +if (type == _tables[7].Table?.Type && string.IsNullOrEmpty(sqlT8) == false) return $"({sqlT8})"; +if (type == _tables[8].Table?.Type && string.IsNullOrEmpty(sqlT9) == false) return $"({sqlT9})"; +if (type == _tables[9].Table?.Type && string.IsNullOrEmpty(sqlT10) == false) return $"({sqlT10})"; +if (type == _tables[10].Table?.Type && string.IsNullOrEmpty(sqlT11) == false) return $"({sqlT11})"; +if (type == _tables[11].Table?.Type && string.IsNullOrEmpty(sqlT12) == false) return $"({sqlT12})"; +if (type == _tables[12].Table?.Type && string.IsNullOrEmpty(sqlT13) == false) return $"({sqlT13})"; +if (type == _tables[13].Table?.Type && string.IsNullOrEmpty(sqlT14) == false) return $"({sqlT14})"; +if (type == _tables[14].Table?.Type && string.IsNullOrEmpty(sqlT15) == false) return $"({sqlT15})"; +if (type == _tables[15].Table?.Type && string.IsNullOrEmpty(sqlT16) == false) return $"({sqlT16})"; return old; }); @@ -7322,7 +7294,7 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.As(string aliasT1, string aliasT2, string aliasT3, string aliasT4, string aliasT5, string aliasT6, string aliasT7, string aliasT8, string aliasT9, string aliasT10, string aliasT11, string aliasT12, string aliasT13, string aliasT14, string aliasT15, string aliasT16) + ISelect ISelect.As(string aliasT1,string aliasT2,string aliasT3,string aliasT4,string aliasT5,string aliasT6,string aliasT7,string aliasT8,string aliasT9,string aliasT10,string aliasT11,string aliasT12,string aliasT13,string aliasT14,string aliasT15,string aliasT16) { if (string.IsNullOrEmpty(aliasT1) == false) _tables[0].Alias = aliasT1; if (string.IsNullOrEmpty(aliasT2) == false) _tables[1].Alias = aliasT2; @@ -7343,167 +7315,167 @@ namespace FreeSql.Internal.CommonProvider return this; } - ISelect ISelect.WithTempQuery(Expression> selector) + ISelect ISelect.WithTempQuery(Expression> selector) { for (var a = 0; a < selector.Parameters.Count; a++) _tables[a].Parameter = selector.Parameters[a]; return this.InternalWithTempQuery(selector); } - double ISelect.Avg(Expression> column) + double ISelect.Avg(Expression> column) { if (column == null) return default(double); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvg(column?.Body); } - ISelectGrouping> ISelect.GroupBy(Expression> exp) + ISelectGrouping> ISelect.GroupBy(Expression> exp) { - if (exp == null) return this.InternalGroupBy>(exp?.Body); + if (exp == null) return this.InternalGroupBy>(exp?.Body); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; - return this.InternalGroupBy>(exp?.Body); + return this.InternalGroupBy>(exp?.Body); } - ISelect ISelect.GroupBySelf(Expression> column) + ISelect ISelect.GroupBySelf(Expression> column) { if (column == null) this.InternalGroupBySelf(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalGroupBySelf(column?.Body); } - TMember ISelect.Max(Expression> column) + TMember ISelect.Max(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMax(column?.Body); } - TMember ISelect.Min(Expression> column) + TMember ISelect.Min(Expression> column) { if (column == null) return default(TMember); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMin(column?.Body); } - ISelect ISelect.OrderBy(Expression> column) + ISelect ISelect.OrderBy(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderBy(column?.Body); } - ISelect ISelect.OrderByDescending(Expression> column) + ISelect ISelect.OrderByDescending(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalOrderByDescending(column?.Body); } - ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression> column, bool descending) { if (condition == false || column == null) return this; for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return descending ? this.InternalOrderByDescending(column?.Body) : this.InternalOrderBy(column?.Body); } - decimal ISelect.Sum(Expression> column) + decimal ISelect.Sum(Expression> column) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSum(column?.Body); } - TReturn ISelect.ToAggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select) + TReturn ISelect.ToAggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select) { if (select == null) return default(TReturn); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregate(select?.Body); } - ISelect ISelect.Aggregate(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, out TReturn result) + ISelect ISelect.Aggregate(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, out TReturn result) { - result = (this as ISelect).ToAggregate(select); + result = (this as ISelect).ToAggregate(select); return this; } - List ISelect.ToList(Expression> select) + List ISelect.ToList(Expression> select) { if (select == null) return this.InternalToList(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToList(select?.Body); } - List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); - Expression> GetToListDtoSelector() + List ISelect.ToList() => (this as ISelect).ToList(GetToListDtoSelector()); + Expression> GetToListDtoSelector() { - return Expression.Lambda>( + return Expression.Lambda>( typeof(TDto).InternalNewExpression(), - _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"), Expression.Parameter(typeof(T2), "b"), Expression.Parameter(typeof(T3), "c"), Expression.Parameter(typeof(T4), "d"), Expression.Parameter(typeof(T5), "e"), Expression.Parameter(typeof(T6), "f"), Expression.Parameter(typeof(T7), "g"), Expression.Parameter(typeof(T8), "h"), Expression.Parameter(typeof(T9), "i"), Expression.Parameter(typeof(T10), "j"), Expression.Parameter(typeof(T11), "k"), Expression.Parameter(typeof(T12), "l"), Expression.Parameter(typeof(T13), "m"), Expression.Parameter(typeof(T14), "n"), Expression.Parameter(typeof(T15), "o"), Expression.Parameter(typeof(T16), "p")); + _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),Expression.Parameter(typeof(T2), "b"),Expression.Parameter(typeof(T3), "c"),Expression.Parameter(typeof(T4), "d"),Expression.Parameter(typeof(T5), "e"),Expression.Parameter(typeof(T6), "f"),Expression.Parameter(typeof(T7), "g"),Expression.Parameter(typeof(T8), "h"),Expression.Parameter(typeof(T9), "i"),Expression.Parameter(typeof(T10), "j"),Expression.Parameter(typeof(T11), "k"),Expression.Parameter(typeof(T12), "l"),Expression.Parameter(typeof(T13), "m"),Expression.Parameter(typeof(T14), "n"),Expression.Parameter(typeof(T15), "o"),Expression.Parameter(typeof(T16), "p")); } - public void ToChunk(Expression> select, int size, Action>> done) + public void ToChunk(Expression> select, int size, Action>> done) { if (select == null || done == null) return; for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; this.InternalToChunk(select.Body, size, done); } - DataTable ISelect.ToDataTable(Expression> select) + DataTable ISelect.ToDataTable(Expression> select) { if (select == null) return this.InternalToDataTable(select?.Body); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTable(select?.Body); } - int ISelect.InsertInto(string tableName, Expression> select) + int ISelect.InsertInto(string tableName, Expression> select) { if (select == null) return this.InternalInsertInto(tableName, select); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertInto(tableName, select?.Body); } - string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression> select, FieldAliasOptions fieldAlias) { if (select == null) return this.InternalToSql(select?.Body, fieldAlias); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToSql(select?.Body, fieldAlias); } - ISelect ISelect.LeftJoin(Expression> exp) + ISelect ISelect.LeftJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); } - - ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression> exp) + + ISelect ISelect.Join(Expression> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.InnerJoin); } - ISelect ISelect.RightJoin(Expression> exp) + ISelect ISelect.RightJoin(Expression> exp) { if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin); } - ISelect ISelect.Where(Expression> exp) + ISelect ISelect.Where(Expression> exp) { if (exp == null) return this.Where(null); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - ISelect ISelect.WhereIf(bool condition, Expression> exp) + ISelect ISelect.WhereIf(bool condition, Expression> exp) { if (condition == false || exp == null) return this; for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; return this.Where(_commonExpression.ExpressionWhereLambda(_tables, _tableRule, exp?.Body, _diymemexpWithTempQuery, _whereGlobalFilter, _params)); } - bool ISelect.Any(Expression> exp) + bool ISelect.Any(Expression> exp) { if (exp == null) return this.Any(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -7513,219 +7485,213 @@ namespace FreeSql.Internal.CommonProvider return ret; } - TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); - - - - + TReturn ISelect.ToOne(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression> select) => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TDto ISelect.First() => (this as ISelect).Limit(1).ToList().FirstOrDefault(); #region HzyTuple 元组 - ISelect ISelect.WithTempQuery(Expression, TDto>> selector) + ISelect ISelect.WithTempQuery(Expression, TDto>> selector) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(selector, _tables); - return (this as ISelect).WithTempQuery((Expression>)expModify); - } + return (this as ISelect).WithTempQuery((Expression>)expModify); + } - double ISelect.Avg(Expression, TMember>> column) + double ISelect.Avg(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Avg((Expression>)expModify); + return (this as ISelect).Avg((Expression>)expModify); } - ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) + ISelectGrouping> ISelect.GroupBy(Expression, TKey>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).GroupBy((Expression>)expModify); + return (this as ISelect).GroupBy((Expression>)expModify); } - ISelect ISelect.GroupBySelf(Expression, TMember>> column) + ISelect ISelect.GroupBySelf(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).GroupBySelf((Expression>)expModify); + return (this as ISelect).GroupBySelf((Expression>)expModify); } - TMember ISelect.Max(Expression, TMember>> column) + TMember ISelect.Max(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Max((Expression>)expModify); + return (this as ISelect).Max((Expression>)expModify); } - TMember ISelect.Min(Expression, TMember>> column) + TMember ISelect.Min(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Min((Expression>)expModify); + return (this as ISelect).Min((Expression>)expModify); } - ISelect ISelect.OrderBy(Expression, TMember>> column) + ISelect ISelect.OrderBy(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderBy((Expression>)expModify); + return (this as ISelect).OrderBy((Expression>)expModify); } - ISelect ISelect.OrderByDescending(Expression, TMember>> column) + ISelect ISelect.OrderByDescending(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByDescending((Expression>)expModify); + return (this as ISelect).OrderByDescending((Expression>)expModify); } - ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) + ISelect ISelect.OrderByIf(bool condition, Expression, TMember>> column, bool descending) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).OrderByIf(condition, (Expression>)expModify, descending); + return (this as ISelect).OrderByIf(condition, (Expression>)expModify,descending); } - decimal ISelect.Sum(Expression, TMember>> column) + decimal ISelect.Sum(Expression, TMember>> column) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).Sum((Expression>)expModify); + return (this as ISelect).Sum((Expression>)expModify); } - List ISelect.ToList(Expression, TReturn>> select) + List ISelect.ToList(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToList((Expression>)expModify); + return (this as ISelect).ToList((Expression>)expModify); } - public void ToChunk(Expression, TReturn>> select, int size, Action>> done) + public void ToChunk(Expression, TReturn>> select, int size, Action>> done) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - (this as ISelect).ToChunk((Expression>)expModify, size, done); + (this as ISelect).ToChunk((Expression>)expModify,size,done); } - DataTable ISelect.ToDataTable(Expression, TReturn>> select) + DataTable ISelect.ToDataTable(Expression, TReturn>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTable((Expression>)expModify); + return (this as ISelect).ToDataTable((Expression>)expModify); } - int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) + int ISelect.InsertInto(string tableName, Expression, TTargetEntity>> select) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertInto(tableName, (Expression>)expModify); + return (this as ISelect).InsertInto(tableName,(Expression>)expModify); } - string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) + string ISelect.ToSql(Expression, TReturn>> select, FieldAliasOptions fieldAlias) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToSql((Expression>)expModify, fieldAlias); + return (this as ISelect).ToSql((Expression>)expModify,fieldAlias); } - ISelect ISelect.LeftJoin(Expression, bool>> exp) + ISelect ISelect.LeftJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).LeftJoin((Expression>)expModify); + return (this as ISelect).LeftJoin((Expression>)expModify); } - - ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); - ISelect ISelect.InnerJoin(Expression, bool>> exp) + + ISelect ISelect.Join(Expression, bool>> exp) => (this as ISelect).InnerJoin(exp); + ISelect ISelect.InnerJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).InnerJoin((Expression>)expModify); + return (this as ISelect).InnerJoin((Expression>)expModify); } - ISelect ISelect.RightJoin(Expression, bool>> exp) + ISelect ISelect.RightJoin(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).RightJoin((Expression>)expModify); + return (this as ISelect).RightJoin((Expression>)expModify); } - ISelect ISelect.Where(Expression, bool>> exp) + ISelect ISelect.Where(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Where((Expression>)expModify); + return (this as ISelect).Where((Expression>)expModify); } - ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) + ISelect ISelect.WhereIf(bool condition, Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).WhereIf(condition, (Expression>)expModify); + return (this as ISelect).WhereIf(condition, (Expression>)expModify); } - bool ISelect.Any(Expression, bool>> exp) + bool ISelect.Any(Expression, bool>> exp) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return (this as ISelect).Any((Expression>)expModify); + return (this as ISelect).Any((Expression>)expModify); } - TReturn ISelect.ToOne(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); - TReturn ISelect.First(Expression, TReturn>> select) - => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.ToOne(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); + TReturn ISelect.First(Expression, TReturn>> select) + => (this as ISelect).Limit(1).ToList(select).FirstOrDefault(); #endregion - - #if net40 #else - Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(double)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalAvgAsync(column?.Body, cancellationToken); } - Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMaxAsync(column?.Body, cancellationToken); } - Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) return Task.FromResult(default(TMember)); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalMinAsync(column?.Body, cancellationToken); } - Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression> column, CancellationToken cancellationToken) { if (column == null) this.InternalOrderBy(column?.Body); for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a]; return this.InternalSumAsync(column?.Body, cancellationToken); } - Task ISelect.ToAggregateAsync(Expression, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToAggregateAsync(Expression,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate,ISelectGroupingAggregate, TReturn>> select, CancellationToken cancellationToken) { if (select == null) return Task.FromResult(default(TReturn)); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToAggregateAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToListAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToListAsync(select?.Body, cancellationToken); } - Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); + Task> ISelect.ToListAsync(CancellationToken cancellationToken) => (this as ISelect).ToListAsync(GetToListDtoSelector(), cancellationToken); - async Task ISelect.ToChunkAsync(Expression> select, int size, Func>, Task> done, CancellationToken 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) + Task ISelect.ToDataTableAsync(Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalToDataTableAsync(select?.Body, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalToDataTableAsync(select?.Body, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression> select, CancellationToken cancellationToken) { if (select == null) return this.InternalInsertIntoAsync(tableName, select, cancellationToken); for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; return this.InternalInsertIntoAsync(tableName, select?.Body, cancellationToken); } - async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression> exp, CancellationToken cancellationToken) { if (exp == null) return await this.AnyAsync(); for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a]; @@ -7735,81 +7701,85 @@ namespace FreeSql.Internal.CommonProvider return ret; } - async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - + async Task ISelect.ToOneAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression> select, CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); #region HzyTuple 元组 - Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).AvgAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MaxAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MaxAsync((Expression>)expModify, cancellationToken); } - Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.MinAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).MinAsync((Expression>)expModify, cancellationToken); } - Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) + Task ISelect.SumAsync(Expression, TMember>> column, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(column, _tables); - return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).SumAsync((Expression>)expModify, cancellationToken); } - Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task> ISelect.ToListAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToListAsync((Expression>)expModify, cancellationToken); } - - Task ISelect.ToChunkAsync(Expression, TReturn>> select, int size, Func>, Task> done, CancellationToken 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); + return (this as ISelect).ToChunkAsync((Expression>)expModify, size, done, cancellationToken); } - Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + Task ISelect.ToDataTableAsync(Expression, TReturn>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); + return (this as ISelect).ToDataTableAsync((Expression>)expModify, cancellationToken); } - Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) + Task ISelect.InsertIntoAsync(string tableName, Expression, TTargetEntity>> select, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(select, _tables); - return (this as ISelect).InsertIntoAsync(tableName, (Expression>)expModify, cancellationToken); + return (this as ISelect).InsertIntoAsync(tableName,(Expression>)expModify, cancellationToken); } - async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) + async Task ISelect.AnyAsync(Expression, bool>> exp, CancellationToken cancellationToken) { var expModify = new CommonExpression.ReplaceHzyTupleToMultiParam().Modify(exp, _tables); - return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); + return await (this as ISelect).AnyAsync((Expression>)expModify, cancellationToken); } - async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) - => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - + async Task ISelect.ToOneAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); + async Task ISelect.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) + => (await (this as ISelect).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif } -} + } diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/ISelect2`16.tt b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/ISelect2`16.tt index fc3503688..7442224f9 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/ISelect2`16.tt +++ b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/ISelect2`16.tt @@ -88,6 +88,10 @@ public interface ISelect<<#=NewStr #>> : ISelect0>, T1> <#= #endif +#if ns21 + IAsyncEnumerable> ToChunkAsyncEnumerable(Expression, TReturn>> select, int size); +#endif + bool Any(Expression, bool>> exp); int InsertInto(string tableName, Expression, TTargetEntity>> select) where TTargetEntity : class; DataTable ToDataTable(Expression, TReturn>> select); diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt index 79dfe5664..345dced53 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt +++ b/FreeSql/Internal/CommonProvider/SelectProvider/T4Temp/Select1Provider2`16.tt @@ -265,10 +265,6 @@ namespace FreeSql.Internal.CommonProvider TReturn ISelect<<#=NewStr #>>.First(Expression, TReturn>> select) => (this as ISelect<<#=NewStr #>>).Limit(1).ToList(select).FirstOrDefault(); TDto ISelect<<#=NewStr #>>.First() => (this as ISelect<<#=NewStr #>>).Limit(1).ToList().FirstOrDefault(); - - - - #region HzyTuple 元组 ISelect ISelect<<#=NewStr #>>.WithTempQuery(Expression>, TDto>> selector) @@ -405,8 +401,6 @@ namespace FreeSql.Internal.CommonProvider #endregion - - #if net40 #else Task ISelect<<#=NewStr #>>.AvgAsync(Expression, TMember>> column, CancellationToken cancellationToken) @@ -487,9 +481,6 @@ namespace FreeSql.Internal.CommonProvider async Task ISelect<<#=NewStr #>>.FirstAsync(Expression, TReturn>> select, CancellationToken cancellationToken) => (await (this as ISelect<<#=NewStr #>>).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); async Task ISelect<<#=NewStr #>>.FirstAsync(CancellationToken cancellationToken) => (await (this as ISelect<<#=NewStr #>>).Limit(1).ToListAsync(cancellationToken)).FirstOrDefault(); - - - #region HzyTuple 元组 Task ISelect<<#=NewStr #>>.AvgAsync(Expression>, TMember>> column, CancellationToken cancellationToken) @@ -551,9 +542,16 @@ namespace FreeSql.Internal.CommonProvider async Task ISelect<<#=NewStr #>>.FirstAsync(Expression>, TReturn>> select, CancellationToken cancellationToken) => (await (this as ISelect<<#=NewStr #>>).Limit(1).ToListAsync(select, cancellationToken)).FirstOrDefault(); - #endregion +#endif + +#if ns21 + public IAsyncEnumerable> ToChunkAsyncEnumerable(Expression, TReturn>> select, int size) + { + for (var a = 0; a < select?.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a]; + return this.InternalToChunkAsyncEnumerable(select?.Body, size); + } #endif }