Add SqlFunc.IsNull

This commit is contained in:
sunkaixuan
2017-11-07 15:17:46 +08:00
parent b1f772acda
commit 42a0611dfe
5 changed files with 12 additions and 0 deletions

View File

@@ -433,6 +433,7 @@ namespace OrmTest.Demo
{ {
var db = GetInstance(); var db = GetInstance();
var t1 = db.Queryable<Student>().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList(); var t1 = db.Queryable<Student>().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList();
var t2 = db.Queryable<Student>().Where(it => SqlFunc.IsNull(it.Name,"nullvalue")=="nullvalue").ToList();
//SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) ) //SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) )
/***More Functions***/ /***More Functions***/

View File

@@ -271,6 +271,13 @@ namespace SqlSugar
return string.Format("{0}", parameter1.MemberValue); return string.Format("{0}", parameter1.MemberValue);
} }
public virtual string IsNull(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter1 = model.Args[1];
return string.Format("ISNULL({0},{1})",parameter.MemberName,parameter1.MemberName);
}
public virtual string True() public virtual string True()
{ {
return "( 1 = 1 ) "; return "( 1 = 1 ) ";

View File

@@ -48,6 +48,7 @@ namespace SqlSugar
string AggregateMax(MethodCallExpressionModel model); string AggregateMax(MethodCallExpressionModel model);
string AggregateCount(MethodCallExpressionModel model); string AggregateCount(MethodCallExpressionModel model);
string MappingColumn(MethodCallExpressionModel model); string MappingColumn(MethodCallExpressionModel model);
string IsNull(MethodCallExpressionModel model);
string GetSelfAndAutoFill(string shortName,bool isSingle); string GetSelfAndAutoFill(string shortName,bool isSingle);
string True(); string True();
string False(); string False();

View File

@@ -67,6 +67,7 @@ namespace SqlSugar
public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); } public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); } public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("Can only be used in expressions"); } public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult IsNull<TResult>(TResult thisValue, TResult ifNullValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static int ToInt32(object value) { return value.ObjToInt(); } public static int ToInt32(object value) { return value.ObjToInt(); }
public static long ToInt64(object value) { return Convert.ToInt64(value); } public static long ToInt64(object value) { return Convert.ToInt64(value); }
/// <summary> /// <summary>

View File

@@ -407,6 +407,8 @@ namespace SqlSugar
Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right"); Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString()); this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
return mappingColumnResult; return mappingColumnResult;
case "IsNull":
return this.Context.DbMehtods.IsNull(model);
case "GetSelfAndAutoFill": case "GetSelfAndAutoFill":
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle); return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle);