mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Synchronous code
This commit is contained in:
@@ -1186,7 +1186,7 @@ namespace SqlSugar
|
||||
var result =await SqlQueryAsync<T, T2, T3, T4, T5, T6, object>(sql, parameters);
|
||||
return new Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5, result.Item6);
|
||||
}
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SqlQueryAsync<T, T2, T3, T4, T5, T6, T7>(string sql, object parameters = null)
|
||||
public virtual async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SqlQueryAsync<T, T2, T3, T4, T5, T6, T7>(string sql, object parameters = null)
|
||||
{
|
||||
var parsmeterArray = this.GetParameters(parameters);
|
||||
this.Context.InitMappingInfo<T>();
|
||||
@@ -1817,7 +1817,7 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private async Task<List<TResult>> GetDataAsync<TResult>(Type entityType, IDataReader dataReader)
|
||||
protected async Task<List<TResult>> GetDataAsync<TResult>(Type entityType, IDataReader dataReader)
|
||||
{
|
||||
List<TResult> result;
|
||||
if (entityType == UtilConstants.DynamicType)
|
||||
|
@@ -200,7 +200,7 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in insertData)
|
||||
{
|
||||
this._Context.Insertable(insertData).ExecuteCommandIdentityIntoEntity();
|
||||
this._Context.Insertable(item).ExecuteCommandIdentityIntoEntity();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -85,7 +85,7 @@ namespace SqlSugar
|
||||
this.Context = UpdateNavProvider._Context;
|
||||
var navColumns = this.Context.EntityMaintenance.GetEntityInfo<Root>().Columns.Where(it => !ignoreColumns.Contains(it.PropertyName) || !ignoreColumns.Any(z => z.EqualCase(it.DbColumnName))).Where(it => it.Navigat != null).ToList();
|
||||
var updateNavs = this;
|
||||
UpdateNavMethodInfo methodInfo = updateNavs.IncludeByNameString(navColumns[0].PropertyName);
|
||||
UpdateNavMethodInfo methodInfo = updateNavs.IncludeByNameString(navColumns[0].PropertyName,updateNavOptions);
|
||||
foreach (var item in navColumns.Skip(1))
|
||||
{
|
||||
methodInfo = methodInfo.IncludeByNameString(item.PropertyName, updateNavOptions);
|
||||
|
@@ -39,12 +39,17 @@ namespace SqlSugar
|
||||
foreach (var item in mappingFieldsExpressions)
|
||||
{
|
||||
InitMappingFieldsExpression(item);
|
||||
var csharpTypeName= UtilMethods.GetUnderType(item.RightEntityColumn.PropertyInfo.PropertyType).Name;
|
||||
if (csharpTypeName .EqualCase(nameof(String)) && item.RightEntityColumn.SqlParameterDbType is System.Data.DbType dbtype)
|
||||
{
|
||||
csharpTypeName =nameof(System.Data.DbType.AnsiString);
|
||||
}
|
||||
clist.Add(new KeyValuePair<WhereType, ConditionalModel>(i==0?WhereType.Or: WhereType.And, new ConditionalModel()
|
||||
{
|
||||
FieldName = item.LeftEntityColumn.DbColumnName,
|
||||
ConditionalType = ConditionalType.Equal,
|
||||
FieldValue = item.RightEntityColumn.PropertyInfo.GetValue(model).ObjToString(),
|
||||
CSharpTypeName =UtilMethods.GetUnderType(item.RightEntityColumn.PropertyInfo.PropertyType).Name
|
||||
CSharpTypeName = csharpTypeName
|
||||
}));
|
||||
i++;
|
||||
}
|
||||
|
@@ -128,6 +128,15 @@ namespace SqlSugar
|
||||
}
|
||||
return this.Clone().Select<int>(" COUNT(1) ").ToList().FirstOrDefault();
|
||||
}
|
||||
if (this.QueryBuilder.AsTables?.Any() == true)
|
||||
{
|
||||
var tableName = this.QueryBuilder.AsTables.FirstOrDefault().Value;
|
||||
if (tableName.StartsWith(" (SELECT * FROM ("))
|
||||
{
|
||||
var list = this.Clone().Select<int>(" COUNT(1) ").ToList();
|
||||
return list.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
MappingTableList expMapping;
|
||||
int result;
|
||||
_CountBegin(out expMapping, out result);
|
||||
@@ -741,6 +750,69 @@ namespace SqlSugar
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
}
|
||||
public async IAsyncEnumerable<T> GetAsyncEnumerable()
|
||||
{
|
||||
var queryable = this.Clone();
|
||||
var sql = queryable.ToSql();
|
||||
var dr = await Context.Ado.GetDataReaderAsync(sql.Key, sql.Value).ConfigureAwait(false);
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var columns = UtilMethods.GetColumnInfo(dr);
|
||||
var cacheKey = "GetAsyncEnumerable" + typeof(T).GetHashCode() + string.Join(",", columns.Select(it => it.Item1 + it.Item2.Name + "_"));
|
||||
IDataReaderEntityBuilder<T> entytyList = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
|
||||
{
|
||||
var cacheResult = new IDataReaderEntityBuilder<T>(this.Context, dr,
|
||||
columns.Select(it => it.Item1).ToList()).CreateBuilder(typeof(T));
|
||||
return cacheResult;
|
||||
});
|
||||
|
||||
|
||||
using (dr)
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
|
||||
var order = entytyList.Build(dr);
|
||||
yield return order;
|
||||
}
|
||||
}
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection)
|
||||
{
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
|
||||
}
|
||||
public IEnumerable<T> GetEnumerable()
|
||||
{
|
||||
var queryable = this.Clone();
|
||||
var sql = queryable.ToSql();
|
||||
var dr = this.Context.Ado.GetDataReader(sql.Key, sql.Value);
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var columns = UtilMethods.GetColumnInfo(dr);
|
||||
var cacheKey = "GetEnumerable" + typeof(T).GetHashCode() + string.Join(",", columns.Select(it => it.Item1 + it.Item2.Name + "_"));
|
||||
IDataReaderEntityBuilder<T> entytyList = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
|
||||
{
|
||||
var cacheResult = new IDataReaderEntityBuilder<T>(this.Context, dr,
|
||||
columns.Select(it => it.Item1).ToList()).CreateBuilder(typeof(T));
|
||||
return cacheResult;
|
||||
});
|
||||
|
||||
|
||||
using (dr)
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
|
||||
var order = entytyList.Build(dr);
|
||||
yield return order;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection)
|
||||
{
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
}
|
||||
public virtual void ForEach(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null)
|
||||
{
|
||||
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0, ErrorMessage.GetThrowMessage("no support Skip take, use PageForEach", "不支持Skip Take,请使用 Queryale.PageForEach"));
|
||||
|
@@ -157,6 +157,15 @@ namespace SqlSugar
|
||||
var list = await this.Clone().Select<int>(" COUNT(1) ").ToListAsync();
|
||||
return list.FirstOrDefault();
|
||||
}
|
||||
if (this.QueryBuilder.AsTables?.Any() == true)
|
||||
{
|
||||
var tableName= this.QueryBuilder.AsTables.FirstOrDefault().Value;
|
||||
if (tableName.StartsWith(" (SELECT * FROM ("))
|
||||
{
|
||||
var list = await this.Clone().Select<int>(" COUNT(1) ").ToListAsync();
|
||||
return list.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
MappingTableList expMapping;
|
||||
int result;
|
||||
_CountBegin(out expMapping, out result);
|
||||
|
@@ -363,6 +363,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
@@ -1197,6 +1198,7 @@ namespace SqlSugar
|
||||
sql = " ";
|
||||
}
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder,clone);
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex;
|
||||
@@ -1211,6 +1213,8 @@ namespace SqlSugar
|
||||
}
|
||||
return this.Select<TResult>(sql);
|
||||
}
|
||||
|
||||
|
||||
public virtual ISugarQueryable<TResult> SelectIF<TResult>(bool condition, Expression<Func<T, T2,T3, TResult>> trueSelectExpression, Expression<Func<T, T2,T3, TResult>> falseSelectExpression)
|
||||
{
|
||||
if (condition)
|
||||
@@ -1928,6 +1932,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -2764,6 +2769,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
|
@@ -376,6 +376,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -1223,6 +1224,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -2085,6 +2087,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -2790,6 +2793,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -3589,6 +3593,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
|
@@ -361,6 +361,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
@@ -993,6 +994,7 @@ namespace SqlSugar
|
||||
{
|
||||
sql = " ";
|
||||
}
|
||||
UtilMethods.UpdateQueryBuilderByClone(this.QueryBuilder, clone);
|
||||
this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters;
|
||||
this.QueryBuilder.SelectNewIgnoreColumns = clone.QueryBuilder.SelectNewIgnoreColumns;
|
||||
this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters;
|
||||
|
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Globalization;
|
||||
using SqlSugar.DbConvert;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class InsertBuilder : IDMLBuilder
|
||||
@@ -324,6 +325,14 @@ namespace SqlSugar
|
||||
var p = ParameterConverter.Invoke(obj, new object[] { columnInfo.Value, GetDbColumnIndex }) as SugarParameter;
|
||||
return p.ParameterName;
|
||||
}
|
||||
else if (columnInfo.SqlParameterDbType is Type t&&t== typeof(EnumToStringConvert) && this.Context?.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString == true)
|
||||
{
|
||||
var pname = Builder.SqlParameterKeyWord + $"{columnInfo.PropertyName}_str" + GetDbColumnIndex;
|
||||
var p = new SugarParameter(pname, columnInfo.Value);
|
||||
this.Parameters.Add(p);
|
||||
GetDbColumnIndex++;
|
||||
return pname;
|
||||
}
|
||||
else if (columnInfo.SqlParameterDbType is Type)
|
||||
{
|
||||
var type = columnInfo.SqlParameterDbType as Type;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar.DbConvert;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -518,6 +519,14 @@ namespace SqlSugar
|
||||
var p = ParameterConverter.Invoke(obj, new object[] { columnInfo.Value, GetDbColumnIndex }) as SugarParameter;
|
||||
return p.ParameterName;
|
||||
}
|
||||
else if (columnInfo.SqlParameterDbType is Type t && t == typeof(EnumToStringConvert) && this.Context?.CurrentConnectionConfig?.MoreSettings?.TableEnumIsString == true)
|
||||
{
|
||||
var pname = Builder.SqlParameterKeyWord + $"{columnInfo.PropertyName}_str" + GetDbColumnIndex;
|
||||
var p = new SugarParameter(pname, columnInfo.Value);
|
||||
this.Parameters.Add(p);
|
||||
GetDbColumnIndex++;
|
||||
return pname;
|
||||
}
|
||||
else if (columnInfo.SqlParameterDbType is Type)
|
||||
{
|
||||
var type = columnInfo.SqlParameterDbType as Type;
|
||||
|
@@ -1860,6 +1860,7 @@ namespace SqlSugar
|
||||
{
|
||||
var result= new SqlSugarClient(UtilMethods.CopyConfig(this.Ado.Context.CurrentConnectionConfig));
|
||||
result.QueryFilter = this.QueryFilter;
|
||||
result.Ado.CommandTimeOut = this.Ado.CommandTimeOut;
|
||||
return result;
|
||||
}
|
||||
public void ThenMapper<T>(IEnumerable<T> list, Action<T> action)
|
||||
|
@@ -39,5 +39,6 @@ namespace SqlSugar
|
||||
public DbType? DatabaseModel { get;set; }
|
||||
public bool ClickHouseEnableFinal { get; set; }
|
||||
public bool EnableJsonb { get; set; }
|
||||
public PostgresIdentityStrategy PostgresIdentityStrategy { get; set; } = PostgresIdentityStrategy.Serial; // 兼容性处理,默认使用Serial
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ namespace SqlSugar
|
||||
NoLike = 13,
|
||||
EqualNull = 14,
|
||||
InLike=15,
|
||||
Range=16
|
||||
Range=16,
|
||||
RangeDate = 17
|
||||
}
|
||||
}
|
||||
|
14
Src/Asp.Net/SqlSugar/Enum/PostgresIdentityStrategy.cs
Normal file
14
Src/Asp.Net/SqlSugar/Enum/PostgresIdentityStrategy.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public enum PostgresIdentityStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// NEXTVAL() function
|
||||
/// </summary>
|
||||
Serial = 1,
|
||||
/// <summary>
|
||||
/// 自增长,PGSQL10+版本最佳实践
|
||||
/// </summary>
|
||||
Identity = 2
|
||||
}
|
||||
}
|
@@ -55,6 +55,14 @@ namespace SqlSugar
|
||||
{
|
||||
value = AppendUnaryExp(parameter, isLeft, value, oppoSiteExpression);
|
||||
}
|
||||
else if (oppoSiteExpression?.Type==UtilConstants.BoolType&&value is bool boolValue && parameter?.BaseParameter?.OperatorValue?.IsIn("AND", "OR")==true)
|
||||
{
|
||||
value = AppendOtherBool(parameter, isLeft, boolValue?" 1=1 ":" 1=2 ");
|
||||
}
|
||||
else if (isLeft==true&& value is bool isTrue && parameter?.BaseParameter?.BaseExpression is BinaryExpression binaryExpression&&binaryExpression.Left is UnaryExpression unaryExpression && unaryExpression.NodeType==ExpressionType.Not&&ExpressionTool.GetParameters(unaryExpression).Count==0)
|
||||
{
|
||||
value = AppendOtherBool(parameter, isLeft, isTrue ? " (1=1) " : " (1=2) ");
|
||||
}
|
||||
else
|
||||
{
|
||||
value = AppendOther(parameter, isLeft, value);
|
||||
@@ -93,6 +101,27 @@ namespace SqlSugar
|
||||
|
||||
return value;
|
||||
}
|
||||
private object AppendOtherBool(ExpressionParameter parameter, bool? isLeft, object value)
|
||||
{
|
||||
//var appendValue = this.Context.SqlParameterKeyWord + ExpressionConst.Const + Context.ParameterIndex;
|
||||
Context.ParameterIndex++;
|
||||
//this.Context.Parameters.Add(new SugarParameter(appendValue, value));
|
||||
var appendValue =value+"";
|
||||
if (isLeft == true)
|
||||
{
|
||||
appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index;
|
||||
}
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Append(appendValue);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
private object AppendUnaryExp(ExpressionParameter parameter, bool? isLeft, object value, Expression oppoSiteExpression)
|
||||
{
|
||||
string appendValue = Context.SqlParameterKeyWord
|
||||
@@ -247,6 +276,14 @@ namespace SqlSugar
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++; ;
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
||||
if (this.BaseParameter?.OppsiteExpression is MemberExpression member&& this.BaseParameter?.BaseExpression is BinaryExpression binary&&ExpressionTool.IsEqualOrLtOrGt(binary))
|
||||
{
|
||||
if (ExpressionTool.IsSqlParameterDbType(this.Context, member))
|
||||
{
|
||||
var p = ExpressionTool.GetParameterBySqlParameterDbType(this.Context.ParameterIndex, paramterValue, this.Context, member);
|
||||
this.Context.Parameters.Last().DbType = p.DbType;
|
||||
}
|
||||
}
|
||||
return parameterName;
|
||||
}
|
||||
protected string AppendParameter(SugarParameter p)
|
||||
|
@@ -321,7 +321,7 @@ namespace SqlSugar
|
||||
DefaultOneToOne(parameter, baseParameter, isLeft, isSetTempData, nav);
|
||||
}
|
||||
}
|
||||
else if (navN.IsNavgate(expression))
|
||||
else if (navN.IsNavgate(expression)&&ExpressionTool.GetParameters(expression).Any())
|
||||
{
|
||||
DefaultOneToOneN(parameter, baseParameter, isLeft, isSetTempData, navN);
|
||||
}
|
||||
@@ -625,6 +625,10 @@ namespace SqlSugar
|
||||
{
|
||||
parameter.CommonTempData = base.AppendParameter(parameter.CommonTempData);
|
||||
}
|
||||
else if (parameter.CommonTempData is MapperSql mapperSql)
|
||||
{
|
||||
parameter.CommonTempData = mapperSql.Sql;
|
||||
}
|
||||
var result = this.Context.DbMehtods.DateValue(new MethodCallExpressionModel()
|
||||
{
|
||||
Conext=this.Context,
|
||||
|
@@ -155,6 +155,13 @@ namespace SqlSugar
|
||||
if (this.Context?.SugarContext?.QueryBuilder?.AppendNavInfo?.MappingNavProperties?.ContainsKey(memberName) == true)
|
||||
{
|
||||
++i;
|
||||
if (this.Context?.SugarContext?.QueryBuilder is QueryBuilder builder&&item is MemberExpression member2&&member2?.Expression is ParameterExpression parameterExpression)
|
||||
{
|
||||
if (builder.SelectNewIgnoreColumns == null)
|
||||
builder.SelectNewIgnoreColumns = new List<KeyValuePair<string, string>>();
|
||||
var p=parameterExpression?.Type?.GetProperty(memberName);
|
||||
builder.SelectNewIgnoreColumns.Add(new KeyValuePair<string, string>(memberName,p?.PropertyType?.Name));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
|
@@ -136,7 +136,14 @@ namespace SqlSugar
|
||||
MapperSql.Sql = $"( {queryable.ToSql().Key} ) ";
|
||||
if (isAny)
|
||||
{
|
||||
MapperSql.Sql = $" EXISTS( {MapperSql.Sql}) ";
|
||||
if (MapperSql.Sql.StartsWith("( ") && MapperSql.Sql.EndsWith(" ) "))
|
||||
{
|
||||
MapperSql.Sql = $" EXISTS {MapperSql.Sql} ";
|
||||
}
|
||||
else
|
||||
{
|
||||
MapperSql.Sql = $" EXISTS( {MapperSql.Sql}) ";
|
||||
}
|
||||
|
||||
}
|
||||
return MapperSql;
|
||||
|
@@ -54,6 +54,14 @@ namespace SqlSugar
|
||||
{
|
||||
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression)?.Expression as ParameterExpression)?.Name;
|
||||
}
|
||||
else if ((meExp.Body is MethodCallExpression methodCallExpression)&&methodCallExpression.Type==UtilConstants.BoolType)
|
||||
{
|
||||
var parameters = ExpressionTool.GetParameters(methodCallExpression);
|
||||
if (context.SingleTableNameSubqueryShortName == null&& parameters?.Select(s=>s.Name)?.Distinct()?.Count()==2)
|
||||
{
|
||||
context.SingleTableNameSubqueryShortName = parameters?.LastOrDefault()?.Name;
|
||||
}
|
||||
}
|
||||
if (ExpressionTool.GetMethodName(context.Expression).IsContainsIn("ToList") && meExp.Parameters.Any(it => it.Name == selfParameterName))
|
||||
{
|
||||
if (meExp.Body is BinaryExpression)
|
||||
|
@@ -546,6 +546,10 @@ namespace SqlSugar
|
||||
if (ignoreColumns.Any())
|
||||
{
|
||||
ignorePropertyNames = ignoreColumns.Select(it => it.Key).ToList();
|
||||
}
|
||||
if (ignorePropertyNames?.Contains(name)==true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval, mappingKeys, ignorePropertyNames));
|
||||
@@ -1331,6 +1335,10 @@ namespace SqlSugar
|
||||
{
|
||||
return UtilMethods.EscapeLikeValue(this.Context, value, wildcard);
|
||||
}
|
||||
public string EscapeLikeValue(string value, char [] wildcards)
|
||||
{
|
||||
return UtilMethods.EscapeLikeValue(this.Context, value, wildcards);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -52,5 +52,6 @@ namespace SqlSugar
|
||||
List<T> ToTree<T>(List<T> list, Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, Expression<Func<T, object>> pkExpression, object rootValue);
|
||||
KeyValuePair<string, SugarParameter[]> ConditionalModelsToSql(List<IConditionalModel> conditionalModels, int beginIndex = 0);
|
||||
string EscapeLikeValue(string value, char wildcard = '%');
|
||||
string EscapeLikeValue(string value,params char[] wildcards);
|
||||
}
|
||||
}
|
||||
|
@@ -173,6 +173,7 @@ namespace SqlSugar
|
||||
ISugarQueryable<T> MergeTable();
|
||||
void ForEachDataReader(Action<T> action);
|
||||
Task ForEachDataReaderAsync(Action<T> action);
|
||||
IEnumerable<T> GetEnumerable();
|
||||
void ForEach(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||
Task ForEachAsync(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||
void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref int totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||
|
@@ -173,6 +173,7 @@
|
||||
<Compile Include="Entities\DefaultCustom.cs" />
|
||||
<Compile Include="Entities\DeleteNavOptions.cs" />
|
||||
<Compile Include="Entities\JoinInfoParameter.cs" />
|
||||
<Compile Include="Enum\PostgresIdentityStrategy.cs" />
|
||||
<Compile Include="Enum\SampleByUnit.cs" />
|
||||
<Compile Include="ExpressionsToSql\Common\ExpressionContextCase.cs" />
|
||||
<Compile Include="ExpressionsToSql\Common\ParameterExpressionVisitor.cs" />
|
||||
|
@@ -1257,6 +1257,7 @@ namespace SqlSugar
|
||||
}
|
||||
var newDb= new SqlSugarClient(connections, _configAction);
|
||||
newDb.QueryFilter = this.QueryFilter;
|
||||
newDb.Ado.CommandTimeOut = this.Ado.CommandTimeOut;
|
||||
return newDb;
|
||||
}
|
||||
|
||||
|
@@ -48,6 +48,7 @@ namespace SqlSugar
|
||||
/// </summary>
|
||||
public class SugarUnitOfWork : IDisposable, ISugarUnitOfWork
|
||||
{
|
||||
private const string TranSuccessEvent = "_sqlSugar_tranSuccessEvent";
|
||||
public ISqlSugarClient Db { get; internal set; }
|
||||
public ITenant Tenant { get; internal set; }
|
||||
public bool IsTran { get; internal set; }
|
||||
@@ -102,6 +103,10 @@ namespace SqlSugar
|
||||
{
|
||||
this.Tenant.CommitTran();
|
||||
IsCommit = true;
|
||||
if (Db.TempItems != null && Db.TempItems.TryGetValue(TranSuccessEvent, out object value) && value != null && value is Action<ISqlSugarClient> eventAction)
|
||||
{
|
||||
eventAction(Db);
|
||||
}
|
||||
}
|
||||
if (this.Db.Ado.Transaction==null&&this.IsClose == false)
|
||||
{
|
||||
@@ -110,5 +115,39 @@ namespace SqlSugar
|
||||
}
|
||||
return IsCommit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事务成功后事件
|
||||
/// </summary>
|
||||
/// <param name="action">需要执行的委托</param>
|
||||
public void AppendTranSuccessEvent(Action<ISqlSugarClient> action)
|
||||
{
|
||||
if (Db.TempItems != null && Db.TempItems.TryGetValue(TranSuccessEvent, out object value) && value != null && value is Action<ISqlSugarClient> eventAction)
|
||||
{
|
||||
eventAction += action;
|
||||
Db.TempItems[TranSuccessEvent] = eventAction;
|
||||
}
|
||||
else if(Db.TempItems != null)
|
||||
{
|
||||
Db.TempItems[TranSuccessEvent] = action;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 减少事务成功后事件
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
public void SubtractTranSuccessEvent(Action<ISqlSugarClient> action)
|
||||
{
|
||||
if (Db.TempItems != null && Db.TempItems.TryGetValue(TranSuccessEvent, out object value) && value != null && value is Action<ISqlSugarClient> eventAction)
|
||||
{
|
||||
eventAction -= action;
|
||||
Db.TempItems[TranSuccessEvent] = eventAction;
|
||||
if (eventAction == null)
|
||||
{
|
||||
Db.TempItems.Remove(TranSuccessEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,23 @@ namespace SqlSugar
|
||||
{
|
||||
public class UtilMethods
|
||||
{
|
||||
|
||||
internal static void SetDefaultValueForBoolean(EntityColumnInfo item, Type propertyType)
|
||||
{
|
||||
if (propertyType == UtilConstants.BoolType && item.DefaultValue != null && item.DefaultValue.EqualCase("true"))
|
||||
{
|
||||
item.DefaultValue = "1";
|
||||
}
|
||||
else if (propertyType == UtilConstants.BoolType && item.DefaultValue != null && item.DefaultValue.EqualCase("false"))
|
||||
{
|
||||
item.DefaultValue = "0";
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateQueryBuilderByClone<TResult>(QueryBuilder queryBuilder,ISugarQueryable<TResult> clone)
|
||||
{
|
||||
queryBuilder.MappingKeys = clone.QueryBuilder.MappingKeys;
|
||||
}
|
||||
public static bool IsKeyValuePairType(Type type)
|
||||
{
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>);
|
||||
@@ -65,6 +82,17 @@ namespace SqlSugar
|
||||
|
||||
return finalTable;
|
||||
}
|
||||
public static string EscapeLikeValue(ISqlSugarClient db, string value,params char[] wildcards)
|
||||
{
|
||||
if (wildcards != null)
|
||||
{
|
||||
foreach (var item in wildcards)
|
||||
{
|
||||
value = EscapeLikeValue(db,value,item);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static string EscapeLikeValue(ISqlSugarClient db, string value, char wildcard='%')
|
||||
{
|
||||
var dbType = db.CurrentConnectionConfig.DbType;
|
||||
@@ -84,6 +112,21 @@ namespace SqlSugar
|
||||
case DbType.Access:
|
||||
case DbType.Odbc:
|
||||
case DbType.TDSQLForPGODBC:
|
||||
|
||||
if (wildcard == ']' || wildcard == '[')
|
||||
{
|
||||
var keyLeft2 = "[[]";
|
||||
var keyRight2 = "[]]";
|
||||
var leftGuid2 = Guid.NewGuid().ToString();
|
||||
var rightGuid2 = Guid.NewGuid().ToString();
|
||||
value = value.Replace(keyLeft2, leftGuid2)
|
||||
.Replace(keyRight2, rightGuid2);
|
||||
|
||||
value = value.Replace(wildcard + "", $"[{wildcard}]");
|
||||
value = value.Replace(leftGuid2, keyLeft2)
|
||||
.Replace(rightGuid2,keyRight2);
|
||||
break;
|
||||
}
|
||||
// SQL Server 使用中括号转义 %, _ 等
|
||||
var keyLeft = "[[]";
|
||||
var keyRight = "[]]";
|
||||
@@ -857,7 +900,8 @@ namespace SqlSugar
|
||||
EnableILike=it.MoreSettings.EnableILike,
|
||||
ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal,
|
||||
PgSqlIsAutoToLowerSchema=it.MoreSettings.PgSqlIsAutoToLowerSchema,
|
||||
EnableJsonb=it.MoreSettings.EnableJsonb
|
||||
EnableJsonb=it.MoreSettings.EnableJsonb,
|
||||
PostgresIdentityStrategy = it.MoreSettings.PostgresIdentityStrategy
|
||||
|
||||
},
|
||||
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
||||
|
Reference in New Issue
Block a user