Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
6e16973277
  1. 30
      OrmTest/ExpressionTest/Method.cs
  2. 3
      SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs
  3. 4
      SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  4. 17
      SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  5. 1
      SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs
  6. 4
      SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

30
OrmTest/ExpressionTest/Method.cs

@ -27,6 +27,7 @@ namespace OrmTest.ExpressionTest
StringIsNullOrEmpty3();
StringIsNullOrEmpty4();
ToUpper();
ToLower();
#endregion
}
base.End("Method Test");
@ -34,15 +35,26 @@ namespace OrmTest.ExpressionTest
private void ToUpper()
{
Expression<Func<Student, bool>> exp = it =>"a"== NBORM.ToLower(it.Id) ;
Expression<Func<Student, bool>> exp = it =>"a"== NBORM.ToUpper(it.Id) ;
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( Id > @Id0 ) OR ( Id='' OR Id IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@Id0",2)
base.Check(value, pars, "( @Const0 = (UPPER(Id)) )", new List<SugarParameter>() {
new SugarParameter("@Const0","a")
}, "ToUpper");
}
private void ToLower()
{
Expression<Func<Student, bool>> exp = it => "a" == NBORM.ToLower(it.Id);
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "( @Const0 = (LOWER(Id)) )", new List<SugarParameter>() {
new SugarParameter("@Const0","a")
}, "ToLower");
}
#region StringIsNullOrEmpty
private void StringIsNullOrEmpty()
@ -63,8 +75,8 @@ namespace OrmTest.ExpressionTest
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodCost1='' OR @MethodCost1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodCost1",true),
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodConst1",true),
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty2");
}
@ -76,8 +88,8 @@ namespace OrmTest.ExpressionTest
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodCost1='' OR @MethodCost1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodCost1",1),
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodConst1",1),
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty3");
}
@ -89,8 +101,8 @@ namespace OrmTest.ExpressionTest
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodCost1='' OR @MethodCost1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodCost1","xx"),
base.Check(value, pars, "(( @Id0 = Id ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List<SugarParameter>() {
new SugarParameter("@MethodConst1","xx"),
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty4");
}

3
SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs

@ -14,7 +14,8 @@ namespace SqlSugar
public const string Format3 = "(";
public const string Format4 = ")";
public const string NBORMFULLNAME = "SqlSugar.NBORM";
public const string METHODCOST = "MethodCost";
public const string METHODCONST = "MethodConst";
public const string CONST = "Const";
public readonly static Type MemberExpressionType = typeof(MemberExpression);
public readonly static Type ConstantExpressionType = typeof(ConstantExpression);
public readonly static Type StringType = typeof(string);

4
SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs

@ -13,13 +13,13 @@ namespace SqlSugar
return string.Format("( {0}='' OR {0} IS NULL )", parameter.Value);
}
public object ToUpper(MethodCallExpressionModel model)
public virtual object ToUpper(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" (UPPER({0})) ", parameter.Value);
}
public object ToLower(MethodCallExpressionModel model)
public virtual object ToLower(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" (LOWER({0})) ", parameter.Value);

17
SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -126,7 +126,22 @@ namespace SqlSugar
}
else
{
var parameterName =this.Context.SqlParameterKeyWord+ExpressionConst.CONST +Context.ParameterIndex;
Context.ParameterIndex++;
this.Context.Parameters.Add(new SugarParameter(parameterName,value));
parameterName = string.Format(" {0} ", parameterName);
if (isLeft == true)
{
parameterName += ExpressionConst.Format1 + parameter.BaseParameter.Index;
}
if (this.Context.Result.Contains(ExpressionConst.Format0))
{
this.Context.Result.Replace(ExpressionConst.Format0, parameterName);
}
else
{
this.Context.Result.Append(parameterName);
}
}
}
}

1
SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs

@ -31,6 +31,7 @@ namespace SqlSugar
{
AppendParameter(parameter, isLeft, value);
}
break;
case ResolveExpressType.FieldSingle:
case ResolveExpressType.FieldMultiple:

4
SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -42,7 +42,7 @@ namespace SqlSugar
}
if (methodCallExpressionArgs.IsMember == false)
{
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.METHODCOST + this.Context.ParameterIndex;
var parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.METHODCONST + this.Context.ParameterIndex;
this.Context.ParameterIndex++;
methodCallExpressionArgs.Value = parameterName;
this.Context.Parameters.Add(new SugarParameter(parameterName, value));
@ -69,6 +69,8 @@ namespace SqlSugar
return this.Context.DbMehtods.IsNullOrEmpty(model);
case "ToLower":
return this.Context.DbMehtods.ToLower(model);
case "ToUpper":
return this.Context.DbMehtods.ToUpper(model);
default:
break;
}

Loading…
Cancel
Save