Update exp to sql

This commit is contained in:
sunkaixuna 2022-01-16 14:10:48 +08:00
parent 1c27b1ab1c
commit 6134010f97
2 changed files with 26 additions and 12 deletions

View File

@ -206,19 +206,28 @@ namespace SqlSugar
else if (type.IsIn(typeof(decimal), typeof(double)))
{
Expression<Func<SingleColumnEntity<object>, object>> exp = it => Convert.ToDecimal(it.ColumnName);
var result = queryBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetResultString();
result = Regex.Replace(result, @"\[ColumnName\]", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\`ColumnName\`", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"""ColumnName""", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
var result = queryBuilder.LambdaExpressions.DbMehtods.ToDecimal(new MethodCallExpressionModel() {
Args=new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){
IsMember=true,
MemberName= formatBuilder.FormatValue(value)
}
}
});
return result;
}
else if (type.IsIn(typeof(DateTime)))
{
Expression<Func<SingleColumnEntity<object>, object>> exp= it => Convert.ToDateTime(it.ColumnName);
var result= queryBuilder.GetExpressionValue(exp,ResolveExpressType.WhereSingle).GetResultString();
result = Regex.Replace(result, @"\[ColumnName\]", formatBuilder.FormatValue(value)+"",RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\`ColumnName\`", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"""ColumnName""", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
Expression<Func<SingleColumnEntity<object>, object>> exp = it => Convert.ToDecimal(it.ColumnName);
var result = queryBuilder.LambdaExpressions.DbMehtods.ToDate(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){
IsMember=true,
MemberName= formatBuilder.FormatValue(value)
}
}
});
return result;
}
else

View File

@ -174,6 +174,11 @@ namespace SqlSugar
}
public virtual object FormatValue(object value)
{
var N = "N";
if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite)
{
N = "";
}
if (value == null)
{
return "NULL";
@ -212,7 +217,7 @@ namespace SqlSugar
}
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{
return "N'" + value.ToString().ToSqlFilter() + "'";
return N+"'" + value.ToString().ToSqlFilter() + "'";
}
else if (type == UtilConstants.DateTimeOffsetType)
{
@ -221,11 +226,11 @@ namespace SqlSugar
}
else if (type == UtilConstants.FloatType)
{
return "N'" +Convert.ToDouble(value).ToString() + "'";
return N+"'" +Convert.ToDouble(value).ToString() + "'";
}
else
{
return "N'" + value.ToString() + "'";
return N+"'" + value.ToString() + "'";
}
}
}