Esempio n. 1
0
        public void Case_Test()
        {
            var dataSet = DataSet <SimpleModel> .Create();

            var dataRow = dataSet.AddRow();

            var      column1 = dataSet._.Column1;
            _Boolean c1      = column1 == 1;
            _Boolean c0      = column1 == 0;
            var      expr    = Case.When(c1).Then(_Boolean.True)
                               .When(c0).Then(_Boolean.False)
                               .Else(_Boolean.Null);
            var dbExpr = (DbCaseExpression)expr.DbExpression;

            dbExpr.Verify(null, c1, _Boolean.True, c0, _Boolean.False, _Boolean.Null);

            column1[dataRow] = 1;
            Assert.AreEqual(true, expr[dataRow]);

            column1[dataRow] = 0;
            Assert.AreEqual(false, expr[dataRow]);

            column1[dataRow] = null;
            Assert.AreEqual(null, expr[dataRow]);
        }
Esempio n. 2
0
        private void TestFromBoolean(_Boolean x, Double?expectedValue)
        {
            _Double expr   = (_Double)x;
            var     dbExpr = (DbCastExpression)expr.DbExpression;

            dbExpr.Verify(x, typeof(bool?), typeof(Double?));
            expr.VerifyEval(expectedValue);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructs SQL WHERE.
        /// </summary>
        /// <param name="condition">The condition.</param>
        /// <returns>This query builder for fluent coding.</returns>
        public DbQueryBuilder Where(_Boolean condition)
        {
            condition.VerifyNotNull(nameof(condition));
            VerifySourceColumn(condition, nameof(condition));
            WhereExpression = And(WhereExpression, EliminateSubQuery(condition.DbExpression));

            return(this);
        }
Esempio n. 4
0
        private void TestFromBoolean(_Boolean x, Int32?expectedValue)
        {
            _Int32 expr   = (_Int32)x;
            var    dbExpr = (DbCastExpression)expr.DbExpression;

            dbExpr.Verify(x, typeof(bool?), typeof(Int32?));
            expr.VerifyEval(expectedValue);
        }
Esempio n. 5
0
        private void TestNot(_Boolean x)
        {
            var expr = !x;

            expr.VerifyEval(!x.Eval());
            var dbExpr = (DbUnaryExpression)expr.DbExpression;

            dbExpr.Verify(DbUnaryExpressionKind.Not, x);
        }
Esempio n. 6
0
        private void TestStringColumnCast(String x, Boolean?expectedValue)
        {
            _String  column1 = _String.Const(x);
            _Boolean expr    = (_Boolean)column1;
            var      dbExpr  = (DbCastExpression)expr.DbExpression;

            dbExpr.Verify(column1, typeof(String), typeof(Boolean?));
            expr.VerifyEval(expectedValue);
        }
Esempio n. 7
0
        private void TestNotEqual(bool?x, bool?y, bool?expectedValue)
        {
            _Boolean column1 = x;
            _Boolean column2 = y;
            var      expr    = column1 != column2;
            var      dbExpr  = (DbBinaryExpression)expr.DbExpression;

            dbExpr.Verify(BinaryExpressionKind.NotEqual, column1, column2);
            expr.VerifyEval(expectedValue);
        }
Esempio n. 8
0
        private void TestAnd(bool?x, bool?y, bool?expectedValue)
        {
            _Boolean left  = x;
            _Boolean right = y;
            var      expr  = left & right;

            expr.VerifyEval(expectedValue);
            var dbExpr = (DbBinaryExpression)expr.DbExpression;

            dbExpr.Verify(BinaryExpressionKind.And, left, right);
        }
Esempio n. 9
0
 private Action <DbQueryBuilder> GetWhereQueryBuilder(_Boolean condition)
 {
     if (condition is null)
     {
         return x => { }
     }
     ;
     else
     {
         return(x => x.Where(condition));
     }
 }
Esempio n. 10
0
        private DbQuery <T> Where(_Boolean condition)
        {
            var queryStatement = GetSimpleQueryStatement(GetWhereQueryBuilder(condition), out T newModel);

            return(DbSession.PerformCreateQuery(newModel, queryStatement));
        }
Esempio n. 11
0
 /// <summary>
 /// Constructs SQL WHERE.
 /// </summary>
 /// <param name="condition">The condition.</param>
 /// <returns>This aggregate query builder for fluent coding.</returns>
 public new DbAggregateQueryBuilder Where(_Boolean condition)
 {
     base.Where(condition);
     return(this);
 }
Esempio n. 12
0
        private void TestImplicit(bool?x)
        {
            _Boolean column = x;

            column.VerifyParam(x);
        }
Esempio n. 13
0
        private void TestParam(bool?x)
        {
            _Boolean column = _Boolean.Param(x);

            column.VerifyParam(x);
        }
Esempio n. 14
0
 /// <summary>
 /// Constructs WHEN statement of CASE expression.
 /// </summary>
 /// <param name="when">The condition.</param>
 /// <returns>A <see cref="CaseWhen"/> struct for further expression construct.</returns>
 public static CaseWhen When(_Boolean when)
 {
     return(new CaseWhen(when));
 }
Esempio n. 15
0
 /// <summary>
 /// Constructs SQL HAVING.
 /// </summary>
 /// <param name="condition">The condition.</param>
 /// <returns>This aggregate query builder for fluent coding.</returns>
 public DbAggregateQueryBuilder Having(_Boolean condition)
 {
     VerifySourceColumn(condition, nameof(condition));
     HavingExpression = EliminateSubQuery(condition.DbExpression);
     return(this);
 }
Esempio n. 16
0
 /// <summary>Creates a column of parameter expression.</summary>
 /// <param name="x">The value of the parameter expression.</param>
 /// <param name="sourceColumn">The value which will be passed to <see cref="DbParamExpression.SourceColumn"/>.</param>
 /// <returns>The column of parameter expression.</returns>
 public static _Boolean Param(bool?x, _Boolean sourceColumn = null)
 {
     return(new ParamExpression <bool?>(x, sourceColumn).MakeColumn <_Boolean>());
 }
Esempio n. 17
0
        private static void TestConst(bool?x)
        {
            _Boolean column = _Boolean.Const(x);

            column.VerifyConst(x);
        }