mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-09-18 17:32:42 +08:00
- 增加 ISelect.InsertInto 将查询转换为 INSERT INTO t1 SELECT ... FROM t2 执行插入;#469
This commit is contained in:
@@ -683,6 +683,61 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var af = this.GetExpressionField(select, fieldAlias);
|
||||
return this.ToSql(af.field);
|
||||
}
|
||||
protected string InternalGetInsertIntoToSql<TTargetEntity>(string tableName, Expression select)
|
||||
{
|
||||
var tb = _orm.CodeFirst.GetTableByEntity(typeof(TTargetEntity));
|
||||
if (tb == null) throw new ArgumentException($"ISelect.InsertInto() 类型错误: {typeof(TTargetEntity).DisplayCsharp()}");
|
||||
if (string.IsNullOrEmpty(tableName)) tableName = tb.DbName;
|
||||
if (_orm.CodeFirst.IsSyncStructureToLower) tableName = tableName.ToLower();
|
||||
if (_orm.CodeFirst.IsSyncStructureToUpper) tableName = tableName.ToUpper();
|
||||
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
var field = new StringBuilder();
|
||||
var index = -10000; //临时规则,不返回 as1
|
||||
|
||||
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, select, null, null, _whereCascadeExpression, null, false); //不走 DTO 映射,不处理 IncludeMany
|
||||
|
||||
var childs = map.Childs;
|
||||
if (childs.Any() == false) throw new ArgumentException($"ISelect.InsertInto() 未选择属性: {typeof(TTargetEntity).DisplayCsharp()}");
|
||||
foreach(var col in tb.Columns.Values)
|
||||
{
|
||||
if (col.Attribute.IsIdentity && string.IsNullOrEmpty(col.DbInsertValue)) continue;
|
||||
if (col.Attribute.CanInsert == false) continue;
|
||||
if (childs.Any(a => a.CsName == col.CsName)) continue;
|
||||
var dbfield = string.IsNullOrWhiteSpace(col.DbInsertValue) == false ? col.DbInsertValue : col.DbDefaultValue;
|
||||
childs.Add(new ReadAnonymousTypeInfo { DbField = dbfield, CsName = col.CsName });
|
||||
}
|
||||
var selectField = string.Join(", ", childs.Select(a => a.DbField));
|
||||
var selectSql = this.ToSql(selectField);
|
||||
var insertField = string.Join(", ", childs.Select(a => _commonUtils.QuoteSqlName(tb.Columns[a.CsName].Attribute.Name)));
|
||||
var sql = $"INSERT INTO {_commonUtils.QuoteSqlName(tableName)}({insertField})\r\n{selectSql}";
|
||||
return sql;
|
||||
}
|
||||
public int InternalInsertInto<TTargetEntity>(string tableName, Expression select)
|
||||
{
|
||||
var sql = this.InternalGetInsertIntoToSql<TTargetEntity>(tableName, select);
|
||||
var dbParms = _params.ToArray();
|
||||
var tb = _orm.CodeFirst.GetTableByEntity(typeof(TTargetEntity));
|
||||
var before = new Aop.CurdBeforeEventArgs(tb.Type, tb, Aop.CurdType.Insert, sql, dbParms);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
int ret = 0;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected DataTable InternalToDataTable(Expression select)
|
||||
{
|
||||
@@ -949,6 +1004,32 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
protected Task<List<TReturn>> InternalToListAsync<TReturn>(Expression select) => this.ToListMapReaderAsync<TReturn>(this.GetExpressionField(select));
|
||||
|
||||
async public Task<int> InternalInsertIntoAsync<TTargetEntity>(string tableName, Expression select)
|
||||
{
|
||||
var sql = this.InternalGetInsertIntoToSql<TTargetEntity>(tableName, select);
|
||||
var dbParms = _params.ToArray();
|
||||
var tb = _orm.CodeFirst.GetTableByEntity(typeof(TTargetEntity));
|
||||
var before = new Aop.CurdBeforeEventArgs(tb.Type, tb, Aop.CurdType.Insert, sql, dbParms);
|
||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||
int ret = 0;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
async protected Task<DataTable> InternalToDataTableAsync(Expression select)
|
||||
{
|
||||
var sql = this.InternalToSql<int>(select, FieldAliasOptions.AsProperty); //DataTable 使用 AsProperty
|
||||
|
@@ -160,6 +160,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -268,6 +275,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -164,6 +164,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -272,6 +279,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -168,6 +168,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -276,6 +283,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -172,6 +172,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -280,6 +287,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -176,6 +176,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -284,6 +291,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -180,6 +180,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -288,6 +295,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -184,6 +184,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -292,6 +299,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -392,6 +392,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
public override List<T1> ToList(bool includeNestedMembers = false) => base.ToList(_isIncluded || includeNestedMembers);
|
||||
|
||||
public int InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, TTargetEntity>> select) where TTargetEntity : class => base.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
|
||||
bool _isIncluded = false;
|
||||
public ISelect<T1> Include<TNavigate>(Expression<Func<T1, TNavigate>> navigateSelector) where TNavigate : class
|
||||
{
|
||||
@@ -1253,6 +1255,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
public Task<List<TDto>> ToListAsync<TDto>() => ToListAsync(GetToListDtoSelector<TDto>());
|
||||
|
||||
public Task<int> InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, TTargetEntity>> select) where TTargetEntity : class => base.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
|
||||
public Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, TReturn>> select)
|
||||
{
|
||||
if (select == null) return this.InternalToDataTableAsync(select?.Body);
|
||||
|
@@ -106,6 +106,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalToList<TReturn>(select?.Body);
|
||||
}
|
||||
|
||||
List<TDto> ISelect<T1, T2>.ToList<TDto>() => (this as ISelect<T1, T2>).ToList(GetToListDtoSelector<TDto>());
|
||||
Expression<Func<T1, T2, TDto>> GetToListDtoSelector<TDto>()
|
||||
{
|
||||
@@ -114,6 +115,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"),
|
||||
Expression.Parameter(typeof(T2), "b"));
|
||||
}
|
||||
|
||||
public void ToChunk<TReturn>(Expression<Func<T1, T2, TReturn>> select, int size, Action<FetchCallbackArgs<List<TReturn>>> done)
|
||||
{
|
||||
if (select == null || done == null) return;
|
||||
@@ -128,6 +130,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2>.ToSql<TReturn>(Expression<Func<T1, T2, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -236,6 +245,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2>.AnyAsync(Expression<Func<T1, T2, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -132,6 +132,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3>.ToSql<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -240,6 +247,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3>.AnyAsync(Expression<Func<T1, T2, T3, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -136,6 +136,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -244,6 +251,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4>.AnyAsync(Expression<Func<T1, T2, T3, T4, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -140,6 +140,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -248,6 +255,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -144,6 +144,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -252,6 +259,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -148,6 +148,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -256,6 +263,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -152,6 +152,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -260,6 +267,13 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
|
@@ -38,15 +38,15 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
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[0].Table?.Type) return $"( {sqlT1} )";
|
||||
if (type == _tables[1].Table?.Type) return $"( {sqlT2} )";
|
||||
if (type == _tables[2].Table?.Type) return $"( {sqlT3} )";
|
||||
if (type == _tables[3].Table?.Type) return $"( {sqlT4} )";
|
||||
if (type == _tables[4].Table?.Type) return $"( {sqlT5} )";
|
||||
if (type == _tables[5].Table?.Type) return $"( {sqlT6} )";
|
||||
if (type == _tables[6].Table?.Type) return $"( {sqlT7} )";
|
||||
if (type == _tables[7].Table?.Type) return $"( {sqlT8} )";
|
||||
if (type == _tables[8].Table?.Type) return $"( {sqlT9} )";
|
||||
return old;
|
||||
});
|
||||
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject($"{sqlT1};\r\n{sqlT2};\r\n{sqlT3};\r\n{sqlT4};\r\n{sqlT5};\r\n{sqlT6};\r\n{sqlT7};\r\n{sqlT8};\r\n{sqlT9}", parms));
|
||||
@@ -55,7 +55,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
double ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.Avg<TMember>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TMember>> column)
|
||||
{
|
||||
if (column == null) return default(double);
|
||||
if (column == null) return 0;
|
||||
for (var a = 0; a < column.Parameters.Count; a++) _tables[a].Parameter = column.Parameters[a];
|
||||
return this.InternalAvg(column?.Body);
|
||||
}
|
||||
@@ -155,6 +155,14 @@ namespace FreeSql.Internal.CommonProvider
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalToDataTable(select?.Body);
|
||||
}
|
||||
|
||||
int ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.InsertInto<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertInto<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertInto<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select, FieldAliasOptions fieldAlias)
|
||||
{
|
||||
if (select == null) return this.InternalToSql<TReturn>(select?.Body, fieldAlias);
|
||||
@@ -168,12 +176,14 @@ namespace FreeSql.Internal.CommonProvider
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin);
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.InnerJoin(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> 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<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.RightJoin(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.InternalJoin(exp?.Body, SelectTableInfoType.LeftJoin);
|
||||
@@ -187,11 +197,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _params));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
if (condition == false || 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, exp?.Body, null, _whereCascadeExpression, _params));
|
||||
return condition ? this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _params)) : this;
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
@@ -210,25 +221,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
#if net40
|
||||
#else
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
var oldwhere = _where.ToString();
|
||||
var ret = await this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _params)).AnyAsync();
|
||||
_where.Clear().Append(oldwhere);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select)
|
||||
{
|
||||
if (select == null) return this.InternalToDataTableAsync(select?.Body);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<List<TDto>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToListAsync<TDto>() => (this as ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>).ToListAsync(GetToListDtoSelector<TDto>());
|
||||
|
||||
Task<double> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.AvgAsync<TMember>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TMember>> column)
|
||||
{
|
||||
if (column == null) return Task.FromResult(default(double));
|
||||
@@ -270,6 +262,31 @@ namespace FreeSql.Internal.CommonProvider
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalToListAsync<TReturn>(select?.Body);
|
||||
}
|
||||
Task<List<TDto>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToListAsync<TDto>() => (this as ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>).ToListAsync(GetToListDtoSelector<TDto>());
|
||||
|
||||
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select)
|
||||
{
|
||||
if (select == null) return this.InternalToDataTableAsync(select?.Body);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalToDataTableAsync(select?.Body);
|
||||
}
|
||||
|
||||
Task<int> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TTargetEntity>> select)
|
||||
{
|
||||
if (select == null) return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select);
|
||||
for (var a = 0; a < select.Parameters.Count; a++) _tables[a].Parameter = select.Parameters[a];
|
||||
return this.InternalInsertIntoAsync<TTargetEntity>(tableName, select?.Body);
|
||||
}
|
||||
|
||||
async Task<bool> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (exp == null) return await this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
var oldwhere = _where.ToString();
|
||||
var ret = await this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _params)).AnyAsync();
|
||||
_where.Clear().Append(oldwhere);
|
||||
return ret;
|
||||
}
|
||||
|
||||
async Task<TReturn> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToOneAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => (await (this as ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>).Limit(1).ToListAsync(select)).FirstOrDefault();
|
||||
async Task<TReturn> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.FirstAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => (await (this as ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>).Limit(1).ToListAsync(select)).FirstOrDefault();
|
||||
|
Reference in New Issue
Block a user