diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs index d87e85709..41ded7e7a 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs @@ -107,23 +107,17 @@ namespace SqlSugar this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); } } + else if (IsConst(item)&&IsConvert(item)&&UtilMethods.IsNullable(item.Type) && UtilMethods.GetUnderType(item.Type)==UtilConstants.BoolType) + { + parameter.Context.Result.Append(base.Context.GetEqString(memberName, GetNewExpressionValue(item))); + } else if (IsConst(item)) { - var oldCommonTempData = parameter.CommonTempData; - if (oldCommonTempData == null) - { - parameter.CommonTempData = CommonTempDataType.Result; - } base.Expression = item; - if (IsConvert(item)) - { - base.Expression = (base.Expression as UnaryExpression).Operand; - } base.Start(); string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex; parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData)); - parameter.CommonTempData = oldCommonTempData; this.Context.ParameterIndex++; } else if (item is MemberExpression) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 7d8cec729..b70be365f 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -417,6 +417,10 @@ namespace SqlSugar { parameter.CommonTempData = GetNewExpressionValue(item); } + else if (IsDateValue(item)) + { + parameter.CommonTempData = GetNewExpressionValue(item); + } else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum()) { parameter.CommonTempData = item.ToString(); @@ -443,7 +447,7 @@ namespace SqlSugar methodCallExpressionArgs.IsMember = false; } } - if (IsDateDate(item)) + if (IsDateDate(item)||IsDateValue(item)) { methodCallExpressionArgs.IsMember = true; } @@ -470,6 +474,15 @@ namespace SqlSugar { return item.Type == UtilConstants.DateType && item is MemberExpression && (item as MemberExpression).Member.Name == "Date"&&item.ToString()!= "DateTime.Now.Date"; } + private static bool IsDateValue(Expression item) + { + return item.Type == UtilConstants.IntType && + item is MemberExpression && + (item as MemberExpression).Expression!=null&& + (item as MemberExpression).Expression.Type==UtilConstants.DateType&& + (item as MemberExpression).Expression is MemberExpression&& + ((item as MemberExpression).Expression as MemberExpression).Member.Name=="Value"; + } private object GetMethodValue(string name, MethodCallExpressionModel model) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs index 19bdfda00..52f7bcf02 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs @@ -93,6 +93,11 @@ namespace SqlSugar return unType != null; } + internal static bool IsNullable(Type type) + { + Type unType = Nullable.GetUnderlyingType(type); + return unType != null; + } internal static T IsNullReturnNew(T returnObj) where T : new() { if (returnObj.IsNullOrEmpty())