Browse Source

Update core

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
923c2242e7
  1. 14
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs
  2. 15
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  3. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

14
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -107,23 +107,17 @@ namespace SqlSugar
this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); 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)) else if (IsConst(item))
{ {
var oldCommonTempData = parameter.CommonTempData;
if (oldCommonTempData == null)
{
parameter.CommonTempData = CommonTempDataType.Result;
}
base.Expression = item; base.Expression = item;
if (IsConvert(item))
{
base.Expression = (base.Expression as UnaryExpression).Operand;
}
base.Start(); base.Start();
string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex; string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData)); this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
parameter.CommonTempData = oldCommonTempData;
this.Context.ParameterIndex++; this.Context.ParameterIndex++;
} }
else if (item is MemberExpression) else if (item is MemberExpression)

15
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -417,6 +417,10 @@ namespace SqlSugar
{ {
parameter.CommonTempData = GetNewExpressionValue(item); 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()) else if (model.Name == "ToString" && item is ConstantExpression && (item as ConstantExpression).Type.IsEnum())
{ {
parameter.CommonTempData = item.ToString(); parameter.CommonTempData = item.ToString();
@ -443,7 +447,7 @@ namespace SqlSugar
methodCallExpressionArgs.IsMember = false; methodCallExpressionArgs.IsMember = false;
} }
} }
if (IsDateDate(item)) if (IsDateDate(item)||IsDateValue(item))
{ {
methodCallExpressionArgs.IsMember = true; 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"; 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) private object GetMethodValue(string name, MethodCallExpressionModel model)
{ {

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

@ -93,6 +93,11 @@ namespace SqlSugar
return unType != null; return unType != null;
} }
internal static bool IsNullable(Type type)
{
Type unType = Nullable.GetUnderlyingType(type);
return unType != null;
}
internal static T IsNullReturnNew<T>(T returnObj) where T : new() internal static T IsNullReturnNew<T>(T returnObj) where T : new()
{ {
if (returnObj.IsNullOrEmpty()) if (returnObj.IsNullOrEmpty())

Loading…
Cancel
Save