Browse Source

Add SqlFunc.HasValue HasNumber

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
af50793708
  1. 27
      SqlServerTest/UnitTest/ExpressionTest/Method.cs
  2. 13
      SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  3. 2
      SqlSugar/ExpressionsToSql/Method/IDbMethods.cs
  4. 2
      SqlSugar/ExpressionsToSql/Method/SqlFunc.cs
  5. 4
      SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

27
SqlServerTest/UnitTest/ExpressionTest/Method.cs

@ -22,6 +22,8 @@ namespace OrmTest.UnitTest
for (int i = 0; i < base.Count; i++)
{
#region StringIsNullOrEmpty
HasValue();
HasNumber();
StringIsNullOrEmpty();
StringIsNullOrEmpty2();
StringIsNullOrEmpty3();
@ -463,6 +465,31 @@ namespace OrmTest.UnitTest
}, "StringIsNullOrEmpty5 error");
}
#endregion
private void HasValue()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.HasValue(it.Name);
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "( [Name]<>'' AND [Name] IS NOT NULL )", new List<SugarParameter>() {
}, "HasValue error");
}
private void HasNumber()
{
Expression<Func<Student, bool>> exp = it => SqlFunc.HasNumber(it.Id);
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(value, pars, "( [Id]>0 AND [Id] IS NOT NULL )", new List<SugarParameter>() {
}, "HasNumber error");
}
}
}

13
SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs

@ -14,6 +14,19 @@ namespace SqlSugar
return string.Format("( {0}='' OR {0} IS NULL )", parameter.MemberName);
}
public virtual string HasValue(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format("( {0}<>'' AND {0} IS NOT NULL )", parameter.MemberName);
}
public virtual string HasNumber(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format("( {0}>0 AND {0} IS NOT NULL )", parameter.MemberName);
}
public virtual string ToUpper(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

2
SqlSugar/ExpressionsToSql/Method/IDbMethods.cs

@ -11,6 +11,8 @@ namespace SqlSugar
{
public interface IDbMethods
{
string HasNumber(MethodCallExpressionModel model);
string HasValue(MethodCallExpressionModel model);
string IsNullOrEmpty(MethodCallExpressionModel model);
string ToLower(MethodCallExpressionModel model);
string ToUpper(MethodCallExpressionModel model);

2
SqlSugar/ExpressionsToSql/Method/SqlFunc.cs

@ -8,6 +8,8 @@ namespace SqlSugar
{
public class SqlFunc
{
public static bool HasNumber(object thisValue) { throw new NotImplementedException(); }
public static bool HasValue(object thisValue){ throw new NotImplementedException(); }
public static bool IsNullOrEmpty(object thisValue) { throw new NotImplementedException(); }
public static string ToLower(object thisValue) { throw new NotImplementedException(); }
public static string ToUpper(object thisValue) { throw new NotImplementedException(); }

4
SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -111,6 +111,10 @@ namespace SqlSugar
{
switch (name)
{
case "HasNumber":
return this.Context.DbMehtods.HasNumber(model);
case "HasValue":
return this.Context.DbMehtods.HasValue(model);
case "IsNullOrEmpty":
return this.Context.DbMehtods.IsNullOrEmpty(model);
case "ToLower":

Loading…
Cancel
Save