Beispiel #1
0
        private void AppendWhereCondition(Expression <Func <TEntity, bool> > conditionExpression)
        {
            string whereCondition = WhereConditionBuilder <TEntity> .FromExpression(conditionExpression);

            string where = $"WHERE {whereCondition}";

            _sqlBuilder.Append(where);
        }
        public void Condition_EqualsConstant_WithAndOperator_Success()
        {
            Expression <Func <TestEntity, bool> > expr
                = e => e.Number1 == 2019 && e.Number2 == 1;

            string expected = "((number1 = 2019) AND (number2 = 1))";

            string result = WhereConditionBuilder <TestEntity> .FromExpression(expr);

            Assert.Equal(
                expected.RemoveWhiteSpaces(),
                result.RemoveWhiteSpaces());
        }
Beispiel #3
0
        public ExistsQuery <TEntity> Where(Expression <Func <TEntity, bool> > conditionExpression)
        {
            if (conditionExpression == null)
            {
                throw new ArgumentNullException("Condition expression must be provided. To select all columns, dont invoke this method.");
            }

            string whereCondition = WhereConditionBuilder <TEntity> .FromExpression(conditionExpression);

            string where = $"WHERE {whereCondition}";

            _sqlBuilder.Append(where);

            return(this);
        }
        public void Condition_EqualsObjPropRef_WithAndOperator_Success()
        {
            var week = new WeekInfo {
                Season = 2019, Week = 1
            };

            Expression <Func <TestEntity, bool> > expr
                = e => e.Number1 == week.Season && e.Number2 == week.Week;

            string expected = "((number1 = 2019) AND (number2 = 1))";

            string result = WhereConditionBuilder <TestEntity> .FromExpression(expr);

            Assert.Equal(
                expected.RemoveWhiteSpaces(),
                result.RemoveWhiteSpaces());
        }
Beispiel #5
0
            public string BuildQuery()
            {
                var table     = MetadataResolver.TableName <TEntity>();
                var selection = PropertySelectionResolver.GetSelectionFromProperty(_selection);

                string selectFrom = $"SELECT {selection} FROM {table}";

                _sqlBuilder.Append(selectFrom);

                if (_where != null)
                {
                    var whereCondition = WhereConditionBuilder <TEntity> .FromExpression(_where);

                    _sqlBuilder.Append($"WHERE {whereCondition}");
                }

                return(_sqlBuilder.GetResult(omitTerminatingSemiColon: true));
            }