mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Add SqlFunc.HasValue HasNumber
This commit is contained in:
parent
8a154ab370
commit
af50793708
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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(); }
|
||||
|
@ -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…
Reference in New Issue
Block a user