Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
af65812971
  1. 24
      OrmTest/ExpressionTest/Method.cs
  2. 12
      SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  3. 2
      SqlSugar/ExpressionsToSql/Method/IDbMethods.cs
  4. 2
      SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

24
OrmTest/ExpressionTest/Method.cs

@ -21,16 +21,20 @@ namespace OrmTest.ExpressionTest
base.Begin();
for (int i = 0; i < base.Count; i++)
{
#region StringIsNullOrEmpty
StringIsNullOrEmpty();
StringIsNullOrEmpty2();
StringIsNullOrEmpty3();
StringIsNullOrEmpty4();
ToUpper();
#endregion
}
base.End("Method Test");
}
private void StringIsNullOrEmpty()
private void ToUpper()
{
Expression<Func<Student, bool>> exp = it =>it.Id>2|| NBORM.IsNullOrEmpty(it.Id);;
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();
@ -40,9 +44,21 @@ namespace OrmTest.ExpressionTest
}, "StringIsNullOrEmpty");
}
#region StringIsNullOrEmpty
private void StringIsNullOrEmpty()
{
Expression<Func<Student, bool>> exp = it => it.Id > 2 || NBORM.IsNullOrEmpty(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)
}, "StringIsNullOrEmpty");
}
private void StringIsNullOrEmpty2()
{
Expression<Func<Student, bool>> exp = it => 2==it.Id || NBORM.IsNullOrEmpty(true); ;
Expression<Func<Student, bool>> exp = it => 2 == it.Id || NBORM.IsNullOrEmpty(true); ;
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
@ -65,7 +81,6 @@ namespace OrmTest.ExpressionTest
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty3");
}
private void StringIsNullOrEmpty4()
{
WhereConst.name = "xx";
@ -79,6 +94,7 @@ namespace OrmTest.ExpressionTest
new SugarParameter("@Id0",2)
}, "StringIsNullOrEmpty4");
}
#endregion
}
}

12
SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs

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

2
SqlSugar/ExpressionsToSql/Method/IDbMethods.cs

@ -12,5 +12,7 @@ namespace SqlSugar
public interface IDbMethods
{
string IsNullOrEmpty(MethodCallExpressionModel model);
object ToLower(MethodCallExpressionModel model);
object ToUpper(MethodCallExpressionModel model);
}
}

2
SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -67,6 +67,8 @@ namespace SqlSugar
{
case "IsNullOrEmpty":
return this.Context.DbMehtods.IsNullOrEmpty(model);
case "ToLower":
return this.Context.DbMehtods.ToLower(model);
default:
break;
}

Loading…
Cancel
Save