mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Synchronous code
This commit is contained in:
@@ -63,7 +63,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
if (this.GetBuider()?.DbFastestProperties?.NoPage == true)
|
if (this.GetBuider()?.DbFastestProperties?.NoPage == true)
|
||||||
{
|
{
|
||||||
Size = int.MaxValue;
|
Size = int.MaxValue/2;
|
||||||
}
|
}
|
||||||
int resul=0;
|
int resul=0;
|
||||||
await this.context.Utilities.PageEachAsync(datas, Size, async item =>
|
await this.context.Utilities.PageEachAsync(datas, Size, async item =>
|
||||||
|
@@ -1110,6 +1110,7 @@ namespace SqlSugar
|
|||||||
public List<string> AutoAppendedColumns { get; set; }
|
public List<string> AutoAppendedColumns { get; set; }
|
||||||
public Dictionary<string, string> MappingKeys { get; set; }
|
public Dictionary<string, string> MappingKeys { get; set; }
|
||||||
public List<KeyValuePair<string,string>> SelectNewIgnoreColumns { get; set; }
|
public List<KeyValuePair<string,string>> SelectNewIgnoreColumns { get; set; }
|
||||||
|
public bool IsAnyParameterExpression { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private string GetTableName(string entityName)
|
private string GetTableName(string entityName)
|
||||||
|
@@ -400,7 +400,12 @@ namespace SqlSugar
|
|||||||
item.FieldValue = "null";
|
item.FieldValue = "null";
|
||||||
}
|
}
|
||||||
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName);
|
builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName);
|
||||||
parameters.Add(new SugarParameter(parameterName, GetFieldValue(item)));
|
var p = new SugarParameter(parameterName, GetFieldValue(item));
|
||||||
|
if (item.CSharpTypeName == "DateOnly")
|
||||||
|
{
|
||||||
|
p.DbType = System.Data.DbType.Date;
|
||||||
|
}
|
||||||
|
parameters.Add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@@ -55,7 +55,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
foreach (var item in keys)
|
foreach (var item in keys)
|
||||||
{
|
{
|
||||||
if (item.ToLower().Contains(likeString.ToLower()))
|
if (item!=null&&item.ToLower().Contains(likeString.ToLower()))
|
||||||
{
|
{
|
||||||
cacheService.Remove<string>(item);
|
cacheService.Remove<string>(item);
|
||||||
}
|
}
|
||||||
|
@@ -55,6 +55,35 @@ namespace SqlSugar
|
|||||||
|
|
||||||
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
|
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
|
||||||
{
|
{
|
||||||
|
if (item is ParameterExpression)
|
||||||
|
{
|
||||||
|
var itemType = item.Type;
|
||||||
|
var ignoreProperty = itemType.GetProperties().FirstOrDefault(it => it.PropertyType == itemType);
|
||||||
|
if (ignoreProperty != null && ignoreProperty.Name != asName)
|
||||||
|
{
|
||||||
|
if (this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns == null)
|
||||||
|
{
|
||||||
|
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns = new List<KeyValuePair<string, string>>();
|
||||||
|
}
|
||||||
|
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns.Add(new KeyValuePair<string, string>(ignoreProperty.Name, itemType.Name));
|
||||||
|
}
|
||||||
|
if (this.Context?.SugarContext?.Context != null)
|
||||||
|
{
|
||||||
|
var entityInfoColumns = this.Context?.SugarContext?.Context.EntityMaintenance.GetEntityInfo(item.Type)
|
||||||
|
.Columns
|
||||||
|
.Where(it=>it.PropertyInfo!=ignoreProperty)
|
||||||
|
.Where(it=>it.IsIgnore==true)
|
||||||
|
.Where(it => it.PropertyInfo.PropertyType.IsClass()).ToList();
|
||||||
|
foreach (var itemColumnInfo in entityInfoColumns)
|
||||||
|
{
|
||||||
|
if (this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns == null)
|
||||||
|
{
|
||||||
|
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns = new List<KeyValuePair<string, string>>();
|
||||||
|
}
|
||||||
|
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns.Add(new KeyValuePair<string, string>(itemColumnInfo.PropertyInfo.Name, itemType.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (item is ConstantExpression)
|
if (item is ConstantExpression)
|
||||||
{
|
{
|
||||||
ResolveConst(parameter, item, asName);
|
ResolveConst(parameter, item, asName);
|
||||||
|
@@ -17,6 +17,7 @@ namespace SqlSugar
|
|||||||
express.IfTrue,
|
express.IfTrue,
|
||||||
express.IfFalse
|
express.IfFalse
|
||||||
};
|
};
|
||||||
|
SetSingleTableNameSubqueryShortName(express);
|
||||||
if (ExpressionTool.GetParameters(express.Test).Count == 0)
|
if (ExpressionTool.GetParameters(express.Test).Count == 0)
|
||||||
{
|
{
|
||||||
while (express != null)
|
while (express != null)
|
||||||
@@ -89,6 +90,46 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetSingleTableNameSubqueryShortName(ConditionalExpression express)
|
||||||
|
{
|
||||||
|
if (this.Context.IsSingle && express.Test is MethodCallExpression callExpression)
|
||||||
|
{
|
||||||
|
var list = callExpression.Arguments.ToList();
|
||||||
|
list.Add(callExpression);
|
||||||
|
if (express.IfTrue is MethodCallExpression callExpressionLeft)
|
||||||
|
{
|
||||||
|
list.Add(callExpressionLeft);
|
||||||
|
list.AddRange(callExpressionLeft.Arguments);
|
||||||
|
}
|
||||||
|
if (express.IfFalse is MethodCallExpression callExpressionRight)
|
||||||
|
{
|
||||||
|
list.Add(callExpressionRight);
|
||||||
|
list.AddRange(callExpressionRight.Arguments);
|
||||||
|
}
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
if (item is MethodCallExpression itemObj)
|
||||||
|
{
|
||||||
|
if (ExpressionTool.IsSubQuery(itemObj))
|
||||||
|
{
|
||||||
|
if (this.Context.SingleTableNameSubqueryShortName == null)
|
||||||
|
{
|
||||||
|
if (this.Context.SugarContext?.QueryBuilder?.SelectValue is LambdaExpression lambda)
|
||||||
|
{
|
||||||
|
if (lambda?.Parameters?.Count == 1)
|
||||||
|
{
|
||||||
|
this.Context.SingleTableNameSubqueryShortName = lambda.Parameters.FirstOrDefault()?.Name;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static bool IsBoolMember(ConditionalExpression express)
|
private static bool IsBoolMember(ConditionalExpression express)
|
||||||
{
|
{
|
||||||
return express.Test is MemberExpression && (express.Test as MemberExpression).Expression is ParameterExpression;
|
return express.Test is MemberExpression && (express.Test as MemberExpression).Expression is ParameterExpression;
|
||||||
|
@@ -322,6 +322,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
private void Select(MemberInitExpression expression, ExpressionParameter parameter, bool isSingle)
|
private void Select(MemberInitExpression expression, ExpressionParameter parameter, bool isSingle)
|
||||||
{
|
{
|
||||||
|
var isAnyParameterExpression = false;
|
||||||
foreach (MemberBinding binding in expression.Bindings)
|
foreach (MemberBinding binding in expression.Bindings)
|
||||||
{
|
{
|
||||||
if (binding.BindingType != MemberBindingType.Assignment)
|
if (binding.BindingType != MemberBindingType.Assignment)
|
||||||
@@ -356,8 +357,16 @@ namespace SqlSugar
|
|||||||
item = (item as UnaryExpression).Operand;
|
item = (item as UnaryExpression).Operand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(item is ParameterExpression)
|
||||||
|
{
|
||||||
|
isAnyParameterExpression = true;
|
||||||
|
}
|
||||||
ResolveNewExpressions(parameter, item, memberName);
|
ResolveNewExpressions(parameter, item, memberName);
|
||||||
}
|
}
|
||||||
|
if (isAnyParameterExpression && this.Context?.SugarContext?.QueryBuilder is QueryBuilder builder)
|
||||||
|
{
|
||||||
|
builder.IsAnyParameterExpression = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsNullable(Type memtype)
|
private static bool IsNullable(Type memtype)
|
||||||
|
@@ -158,19 +158,6 @@ namespace SqlSugar
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
if (item is ParameterExpression)
|
|
||||||
{
|
|
||||||
var itemType = item.Type;
|
|
||||||
var ignoreProperty = itemType.GetProperties().FirstOrDefault(it => it.PropertyType == itemType);
|
|
||||||
if (ignoreProperty!=null&& ignoreProperty.Name!=memberName)
|
|
||||||
{
|
|
||||||
if (this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns == null)
|
|
||||||
{
|
|
||||||
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns = new List<KeyValuePair<string, string>>();
|
|
||||||
}
|
|
||||||
this.Context.SugarContext.QueryBuilder.SelectNewIgnoreColumns.Add(new KeyValuePair<string, string>(ignoreProperty.Name, itemType.Name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResolveNewExpressions(parameter, item, memberName);
|
ResolveNewExpressions(parameter, item, memberName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -264,6 +264,28 @@ namespace SqlSugar
|
|||||||
var tType = typeof(T);
|
var tType = typeof(T);
|
||||||
var classProperties = tType.GetProperties()
|
var classProperties = tType.GetProperties()
|
||||||
.Where(p => p.GetIndexParameters().Length == 0).ToList();
|
.Where(p => p.GetIndexParameters().Length == 0).ToList();
|
||||||
|
if(this.QueryBuilder is QueryBuilder q)
|
||||||
|
{
|
||||||
|
if (q.IsAnyParameterExpression)
|
||||||
|
{
|
||||||
|
if (q.SelectValue is LambdaExpression lambda)
|
||||||
|
{
|
||||||
|
if (lambda.Body is MemberInitExpression memberInit)
|
||||||
|
{
|
||||||
|
// 获取memberInit中定义的属性名称
|
||||||
|
var memberNames = memberInit.Bindings
|
||||||
|
.OfType<MemberAssignment>()
|
||||||
|
.Select(b => b.Member.Name)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// 过滤掉不在memberInit中的属性
|
||||||
|
classProperties = classProperties
|
||||||
|
.Where(p => memberNames.Contains(p.Name))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
var reval = new List<T>();
|
var reval = new List<T>();
|
||||||
if (reader != null && !reader.IsClosed)
|
if (reader != null && !reader.IsClosed)
|
||||||
{
|
{
|
||||||
@@ -533,7 +555,7 @@ namespace SqlSugar
|
|||||||
var type = UtilMethods.GetUnderType(item.PropertyType);
|
var type = UtilMethods.GetUnderType(item.PropertyType);
|
||||||
if (addValue == DBNull.Value || addValue == null)
|
if (addValue == DBNull.Value || addValue == null)
|
||||||
{
|
{
|
||||||
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
if (item.PropertyType.IsIn(UtilConstants.IntType,UtilConstants.LongType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
|
||||||
{
|
{
|
||||||
addValue = 0;
|
addValue = 0;
|
||||||
}
|
}
|
||||||
|
@@ -122,7 +122,7 @@ namespace SqlSugar
|
|||||||
case DbType.Vastbase:
|
case DbType.Vastbase:
|
||||||
default:
|
default:
|
||||||
value = value
|
value = value
|
||||||
.Replace(wildcardStr, "\\\\" + wildcard);
|
.Replace(wildcardStr, "\\" + wildcard);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1476,6 +1476,10 @@ namespace SqlSugar
|
|||||||
CSharpTypeName = ctypename,
|
CSharpTypeName = ctypename,
|
||||||
FieldValue = value
|
FieldValue = value
|
||||||
};
|
};
|
||||||
|
if (ctypename == "DateOnly")
|
||||||
|
{
|
||||||
|
return Convert.ToDateTime(value);
|
||||||
|
}
|
||||||
if (item.FieldValue == string.Empty && item.CSharpTypeName.HasValue() && !item.CSharpTypeName.EqualCase("string"))
|
if (item.FieldValue == string.Empty && item.CSharpTypeName.HasValue() && !item.CSharpTypeName.EqualCase("string"))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user