Add SqlFunc.HasValue HasNumber

This commit is contained in:
sunkaixuan 2017-06-04 09:27:41 +08:00
parent 8a154ab370
commit af50793708
5 changed files with 48 additions and 0 deletions

View File

@ -22,6 +22,8 @@ namespace OrmTest.UnitTest
for (int i = 0; i < base.Count; i++) for (int i = 0; i < base.Count; i++)
{ {
#region StringIsNullOrEmpty #region StringIsNullOrEmpty
HasValue();
HasNumber();
StringIsNullOrEmpty(); StringIsNullOrEmpty();
StringIsNullOrEmpty2(); StringIsNullOrEmpty2();
StringIsNullOrEmpty3(); StringIsNullOrEmpty3();
@ -463,6 +465,31 @@ namespace OrmTest.UnitTest
}, "StringIsNullOrEmpty5 error"); }, "StringIsNullOrEmpty5 error");
} }
#endregion #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");
}
} }
} }

View File

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

View File

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

View File

@ -8,6 +8,8 @@ namespace SqlSugar
{ {
public class SqlFunc 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 bool IsNullOrEmpty(object thisValue) { throw new NotImplementedException(); }
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(); }

View File

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