mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-26 13:43:10 +08:00
-
This commit is contained in:
@@ -119,6 +119,8 @@ namespace OrmTest.Demo
|
||||
{
|
||||
var db = GetInstance();
|
||||
var getAll = db.Queryable<Student>().ToList();
|
||||
var getId = db.Queryable<Student>().Select(it => it.Id).ToList();
|
||||
// var getIdIIF= db.Queryable<Student>().Select(it =>new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id) }).ToList();
|
||||
var getAllNoLock = db.Queryable<Student>().With(SqlWith.NoLock).ToList();
|
||||
var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
|
||||
var getSingleOrDefault = db.Queryable<Student>().Single();
|
||||
|
||||
@@ -497,32 +497,34 @@ namespace OrmTest.UnitTest
|
||||
|
||||
private void IIF()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2);
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(it.Id == 1, 1, 2)==1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( CASE WHEN ( [Id] = @Id1 ) THEN @MethodConst2 ELSE @MethodConst3 END )", new List<SugarParameter>()
|
||||
base.Check(value, pars, "(( CASE WHEN ( [Id] = @Id1 ) THEN @MethodConst2 ELSE @MethodConst3 END ) = @Const4 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@Id1",1),
|
||||
new SugarParameter("@MethodConst2",1),
|
||||
new SugarParameter("@MethodConst3",2)
|
||||
new SugarParameter("@MethodConst3",2),
|
||||
new SugarParameter("@Const4",1)
|
||||
}, "IIF error");
|
||||
}
|
||||
|
||||
private void IIF2()
|
||||
{
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name,"a"), 1, 2);
|
||||
Expression<Func<Student, bool>> exp = it => SqlFunc.IIF(SqlFunc.Contains(it.Name,"a"), 1, 2)==1;
|
||||
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
|
||||
expContext.Resolve(exp, ResolveExpressType.WhereSingle);
|
||||
var value = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
base.Check(value, pars, "( CASE WHEN ([Name] like '%'+@MethodConst1+'%') THEN @MethodConst2 ELSE @MethodConst3 END )", new List<SugarParameter>()
|
||||
base.Check(value, pars, "(( CASE WHEN ([Name] like '%'+@MethodConst1+'%') THEN @MethodConst2 ELSE @MethodConst3 END ) = @Const4 )", new List<SugarParameter>()
|
||||
{
|
||||
new SugarParameter("@MethodConst1","a"),
|
||||
new SugarParameter("@MethodConst2",1),
|
||||
new SugarParameter("@MethodConst3",2)
|
||||
}, "IIF error");
|
||||
new SugarParameter("@MethodConst3",2),
|
||||
new SugarParameter("@Const4",1)
|
||||
}, "IIF2 error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace SqlSugar
|
||||
public static DateTime DateAdd(DateTime date, int addValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static bool Between(object value, object start, object end) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static bool IIF(bool Expression, object thenValue, object elseValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("This method is not supported by the current parameter"); }
|
||||
public static int ToInt32(object value) { return value.ObjToInt(); }
|
||||
public static long ToInt64(object value) { return Convert.ToInt64(value); }
|
||||
public static DateTime ToDate(object value) { return value.ObjToDate(); }
|
||||
|
||||
Reference in New Issue
Block a user