mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 04:35:29 +08:00
Synchronous code
This commit is contained in:
parent
5992cd11bd
commit
7f07b2d42f
@ -742,6 +742,10 @@ namespace SqlSugar
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (dataType.EqualCase("timestamp") && properyTypeName.EqualCase("timestamptz"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return properyTypeName.ToLower() != dataType.ToLower();
|
||||
|
@ -356,14 +356,16 @@ namespace SqlSugar
|
||||
|
||||
private async Task<int> _BulkUpdate(List<T> datas, string[] whereColumns, string[] updateColumns)
|
||||
{
|
||||
var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection;
|
||||
var isAutoOk = false;
|
||||
var old = this.context.Ado.IsDisableMasterSlaveSeparation;
|
||||
var oldOk = false;
|
||||
try
|
||||
{
|
||||
Begin(datas, false);
|
||||
Check.Exception(whereColumns == null || whereColumns.Count() == 0, "where columns count=0 or need primary key");
|
||||
Check.Exception(updateColumns == null || updateColumns.Count() == 0, "set columns count=0");
|
||||
var isAuto = this.context.CurrentConnectionConfig.IsAutoCloseConnection;
|
||||
this.context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
var old = this.context.Ado.IsDisableMasterSlaveSeparation;
|
||||
this.context.Ado.IsDisableMasterSlaveSeparation = true;
|
||||
DataTable dt = ToDdateTable(datas);
|
||||
IFastBuilder buider = GetBuider();
|
||||
@ -378,8 +380,10 @@ namespace SqlSugar
|
||||
this.context.DbMaintenance.DropTable(dt.TableName);
|
||||
}
|
||||
this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
|
||||
isAutoOk = true;
|
||||
buider.CloseDb();
|
||||
this.context.Ado.IsDisableMasterSlaveSeparation = old;
|
||||
oldOk = true;
|
||||
End(datas, false);
|
||||
return result;
|
||||
}
|
||||
@ -388,6 +392,14 @@ namespace SqlSugar
|
||||
this.context.Close();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(!isAutoOk)
|
||||
this.context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto;
|
||||
if (!oldOk)
|
||||
this.context.Ado.IsDisableMasterSlaveSeparation = old;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ActionIgnoreColums(string[] whereColumns, string[] updateColumns, DataTable dt,bool IsActionUpdateColumns)
|
||||
|
@ -37,7 +37,7 @@ namespace SqlSugar
|
||||
if (list == null) return default(T);
|
||||
else return list.SingleOrDefault();
|
||||
}
|
||||
public async Task<T> SingleAsync()
|
||||
public virtual async Task<T> SingleAsync()
|
||||
{
|
||||
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
|
||||
{
|
||||
@ -67,19 +67,19 @@ namespace SqlSugar
|
||||
return result.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
public async Task<T> SingleAsync(Expression<Func<T, bool>> expression)
|
||||
public virtual async Task<T> SingleAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
_Where(expression);
|
||||
var result = await SingleAsync();
|
||||
this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last());
|
||||
return result;
|
||||
}
|
||||
public Task<T> FirstAsync(CancellationToken token)
|
||||
public virtual Task<T> FirstAsync(CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = token;
|
||||
return FirstAsync();
|
||||
}
|
||||
public async Task<T> FirstAsync()
|
||||
public virtual async Task<T> FirstAsync()
|
||||
{
|
||||
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
|
||||
{
|
||||
@ -102,12 +102,12 @@ namespace SqlSugar
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
public Task<T> FirstAsync(Expression<Func<T, bool>> expression, CancellationToken token)
|
||||
public virtual Task<T> FirstAsync(Expression<Func<T, bool>> expression, CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = token;
|
||||
return FirstAsync(expression);
|
||||
}
|
||||
public async Task<T> FirstAsync(Expression<Func<T, bool>> expression)
|
||||
public virtual async Task<T> FirstAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
_Where(expression);
|
||||
var result = await FirstAsync();
|
||||
@ -115,7 +115,7 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> AnyAsync(Expression<Func<T, bool>> expression)
|
||||
public virtual async Task<bool> AnyAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
_Where(expression);
|
||||
var result = await AnyAsync();
|
||||
@ -123,23 +123,23 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<bool> AnyAsync(Expression<Func<T, bool>> expression, CancellationToken token)
|
||||
public virtual Task<bool> AnyAsync(Expression<Func<T, bool>> expression, CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = token;
|
||||
return AnyAsync(expression);
|
||||
}
|
||||
|
||||
public async Task<bool> AnyAsync()
|
||||
public virtual async Task<bool> AnyAsync()
|
||||
{
|
||||
return (await this.Clone().Take(1).Select("1").ToListAsync()).Count() > 0; ;
|
||||
}
|
||||
|
||||
public Task<int> CountAsync(CancellationToken token)
|
||||
public virtual Task<int> CountAsync(CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = token;
|
||||
return CountAsync();
|
||||
}
|
||||
public async Task<int> CountAsync()
|
||||
public virtual async Task<int> CountAsync()
|
||||
{
|
||||
if (this.QueryBuilder.Skip == null &&
|
||||
this.QueryBuilder.Take == null &&
|
||||
@ -181,7 +181,7 @@ namespace SqlSugar
|
||||
return CountAsync(expression);
|
||||
}
|
||||
|
||||
public async Task<TResult> MaxAsync<TResult>(string maxField)
|
||||
public virtual async Task<TResult> MaxAsync<TResult>(string maxField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.MaxTemplate, maxField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
@ -189,55 +189,55 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<TResult> MaxAsync<TResult>(string maxField, CancellationToken token)
|
||||
public virtual Task<TResult> MaxAsync<TResult>(string maxField, CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken= token;
|
||||
return MaxAsync<TResult>(maxField);
|
||||
}
|
||||
|
||||
public Task<TResult> MaxAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
public virtual Task<TResult> MaxAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return _MaxAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public Task<TResult> MaxAsync<TResult>(Expression<Func<T, TResult>> expression, CancellationToken token)
|
||||
public virtual Task<TResult> MaxAsync<TResult>(Expression<Func<T, TResult>> expression, CancellationToken token)
|
||||
{
|
||||
this.Context.Ado.CancellationToken = token;
|
||||
return MaxAsync(expression);
|
||||
}
|
||||
|
||||
public async Task<TResult> MinAsync<TResult>(string minField)
|
||||
public virtual async Task<TResult> MinAsync<TResult>(string minField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.MinTemplate, minField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
public Task<TResult> MinAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
public virtual Task<TResult> MinAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return _MinAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public async Task<TResult> SumAsync<TResult>(string sumField)
|
||||
public virtual async Task<TResult> SumAsync<TResult>(string sumField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.SumTemplate, sumField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
public Task<TResult> SumAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
public virtual Task<TResult> SumAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return _SumAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public async Task<TResult> AvgAsync<TResult>(string avgField)
|
||||
public virtual async Task<TResult> AvgAsync<TResult>(string avgField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.AvgTemplate, avgField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
public Task<TResult> AvgAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
public virtual Task<TResult> AvgAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return _AvgAsync<TResult>(expression);
|
||||
}
|
||||
|
@ -401,10 +401,14 @@ namespace SqlSugar
|
||||
}
|
||||
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName);
|
||||
var p = new SugarParameter(parameterName, GetFieldValue(item));
|
||||
if (item.CSharpTypeName == "DateOnly")
|
||||
if (item.CSharpTypeName .EqualCase("DateOnly"))
|
||||
{
|
||||
p.DbType = System.Data.DbType.Date;
|
||||
}
|
||||
if (item.CSharpTypeName.EqualCase("Char"))
|
||||
{
|
||||
p.DbType = System.Data.DbType.StringFixedLength;
|
||||
}
|
||||
parameters.Add(p);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace SqlSugar
|
||||
public class ConfigQuery
|
||||
{
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public void SetTable<T>(Expression<Func<T, object>> keyExpression, Expression<Func<T, object>> valueTextExpression, string uniqueCode = null, Expression<Func<T, object>> whereExpression=null)
|
||||
public void SetTable<T>(Expression<Func<T, object>> keyExpression, Expression<Func<T, object>> valueTextExpression, string uniqueCode = null, Expression<Func<T, object>> whereExpression=null,string asTableName=null)
|
||||
{
|
||||
lock (SqlFuncExtendsion.TableInfos)
|
||||
{
|
||||
@ -29,7 +29,7 @@ namespace SqlSugar
|
||||
SqlFuncExtendsion.TableInfos.Add(new ConfigTableInfo()
|
||||
{
|
||||
Type = typeof(T),
|
||||
TableName = entity.DbTableName,
|
||||
TableName =asTableName??entity.DbTableName,
|
||||
Key = keyValue,
|
||||
Value = ValueValue,
|
||||
Where = where,
|
||||
|
@ -38,5 +38,6 @@ namespace SqlSugar
|
||||
public bool DisableQueryWhereColumnRemoveTrim { get; set; }
|
||||
public DbType? DatabaseModel { get;set; }
|
||||
public bool ClickHouseEnableFinal { get; set; }
|
||||
public bool EnableJsonb { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,26 @@ namespace SqlSugar
|
||||
public string GetValue(Expression expression = null)
|
||||
{
|
||||
var exp = expression as MethodCallExpression;
|
||||
return "AVG(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")";
|
||||
var argExp = exp.Arguments[0];
|
||||
var parametres = (argExp as LambdaExpression).Parameters;
|
||||
if ((argExp as LambdaExpression).Body is UnaryExpression)
|
||||
{
|
||||
argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand;
|
||||
}
|
||||
var argLambda = argExp as LambdaExpression;
|
||||
if (this.Context.InitMappingInfo != null && argLambda != null && argLambda.Parameters.Count > 0)
|
||||
{
|
||||
foreach (var item in argLambda.Parameters)
|
||||
{
|
||||
this.Context.InitMappingInfo(item.Type);
|
||||
}
|
||||
this.Context.RefreshMapping();
|
||||
}
|
||||
var result = "AVG(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")";
|
||||
var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;
|
||||
if (this.Context.JoinIndex == 0)
|
||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -848,7 +848,8 @@ namespace SqlSugar
|
||||
DatabaseModel=it.MoreSettings.DatabaseModel,
|
||||
EnableILike=it.MoreSettings.EnableILike,
|
||||
ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal,
|
||||
PgSqlIsAutoToLowerSchema=it.MoreSettings.PgSqlIsAutoToLowerSchema
|
||||
PgSqlIsAutoToLowerSchema=it.MoreSettings.PgSqlIsAutoToLowerSchema,
|
||||
EnableJsonb=it.MoreSettings.EnableJsonb
|
||||
|
||||
},
|
||||
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
||||
|
Loading…
Reference in New Issue
Block a user