This commit is contained in:
sunkaixuan
2017-01-31 20:39:57 +08:00
parent 1dd61d638d
commit 64df886d0f
5 changed files with 25 additions and 0 deletions

View File

@@ -29,10 +29,24 @@ namespace OrmTest.ExpressionTest
ToUpper(); ToUpper();
ToLower(); ToLower();
Trim(); Trim();
Contains();
#endregion #endregion
} }
base.End("Method Test"); base.End("Method Test");
} }
private void Contains()
{
Expression<Func<Student, bool>> exp = it => NBORM.Contains(it.Name,"a");
SqlServerExpressionContext expContext = new SqlServerExpressionContext(exp, ResolveExpressType.WhereSingle);
expContext.Resolve();
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = Name )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0"," a")
}, "Contains");
}
private void Trim() private void Trim()
{ {
Expression<Func<Student, bool>> exp = it =>NBORM.Trim(" a")==it.Name; Expression<Func<Student, bool>> exp = it =>NBORM.Trim(" a")==it.Name;

View File

@@ -30,5 +30,12 @@ namespace SqlSugar
var parameter = model.Args[0]; var parameter = model.Args[0];
return string.Format(" (rtrim(ltrim({0}))) ", parameter.Value); return string.Format(" (rtrim(ltrim({0}))) ", parameter.Value);
} }
public virtual object Contains(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[0];
return string.Format(" {0} like '%'+{1}+'%' ", parameter.Value, parameter2.Value);
}
} }
} }

View File

@@ -15,5 +15,6 @@ namespace SqlSugar
object ToLower(MethodCallExpressionModel model); object ToLower(MethodCallExpressionModel model);
object ToUpper(MethodCallExpressionModel model); object ToUpper(MethodCallExpressionModel model);
object Trim(MethodCallExpressionModel model); object Trim(MethodCallExpressionModel model);
object Contains(MethodCallExpressionModel model);
} }
} }

View File

@@ -12,5 +12,6 @@ namespace SqlSugar
public static string ToLower(object thisValue) { throw new NotImplementedException(); } public static string ToLower(object thisValue) { throw new NotImplementedException(); }
public static string ToUpper(object thisValue) { throw new NotImplementedException(); } public static string ToUpper(object thisValue) { throw new NotImplementedException(); }
public static string Trim(object thisValue) { throw new NotImplementedException(); } public static string Trim(object thisValue) { throw new NotImplementedException(); }
public static bool Contains(string thisValue, string parameterValue) { throw new NotImplementedException();}
} }
} }

View File

@@ -76,6 +76,8 @@ namespace SqlSugar
return this.Context.DbMehtods.ToUpper(model); return this.Context.DbMehtods.ToUpper(model);
case "Trim": case "Trim":
return this.Context.DbMehtods.Trim(model); return this.Context.DbMehtods.Trim(model);
case "Contains":
return this.Context.DbMehtods.Contains(model);
default: default:
break; break;
} }