Browse Source

Update exp to sql

pull/18/head
sunkaixuan 3 years ago
parent
commit
8a72f18798
  1. 42
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

42
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs

@ -135,19 +135,7 @@ namespace SqlSugar
string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
var addItem = new SugarParameter(parameterName, parameter.CommonTempData);
var dataType = UtilMethods.GetUnderType(item.Type);
if (addItem.Value == null && dataType == UtilConstants.DateType)
{
addItem.DbType = System.Data.DbType.Date;
}
if (addItem.Value == null && dataType.IsIn(UtilConstants.FloatType,UtilConstants.IntType,UtilConstants.LongType,UtilConstants.DecType,UtilConstants.DobType))
{
addItem.DbType = System.Data.DbType.Int32;
}
if (addItem.Value == null && dataType == UtilConstants.BoolType)
{
addItem.DbType = System.Data.DbType.Boolean;
}
ConvertParameterTypeByType(item, addItem);
this.Context.Parameters.Add(addItem);
this.Context.ParameterIndex++;
@ -163,6 +151,16 @@ namespace SqlSugar
base.Start();
parameter.IsAppendResult();
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString()));
if (this.Context.Parameters != null)
{
var memberParameter = this.Context.Parameters?.FirstOrDefault(it =>it.Value==null && it.ParameterName == parameter.CommonTempData.ObjToString());
if (memberParameter != null)
{
ConvertParameterTypeByType(item, memberParameter);
}
}
base.Context.Result.CurrentParameter = null;
}
}
@ -208,6 +206,24 @@ namespace SqlSugar
}
}
}
private static void ConvertParameterTypeByType(Expression item, SugarParameter addItem)
{
var dataType = UtilMethods.GetUnderType(item.Type);
if (addItem.Value == null && dataType == UtilConstants.DateType)
{
addItem.DbType = System.Data.DbType.Date;
}
if (addItem.Value == null && dataType.IsIn(UtilConstants.FloatType, UtilConstants.IntType, UtilConstants.LongType, UtilConstants.DecType, UtilConstants.DobType))
{
addItem.DbType = System.Data.DbType.Int32;
}
if (addItem.Value == null && dataType == UtilConstants.BoolType)
{
addItem.DbType = System.Data.DbType.Boolean;
}
}
private static bool IsConst(Expression item)
{
return item is UnaryExpression || item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant;

Loading…
Cancel
Save