Esempio n. 1
0
        private static string GetQuery(QueryExpressions expressions, Dictionary <string, object> queryParameters)
        {
            var queryBuilder = new StringBuilder("SELECT * FROM root r");

            if (expressions.WhereExpressions?.Any() == true)
            {
                queryBuilder.Append(" WHERE ");

                queryBuilder.Append(
                    QueryWhereClauseVisitor.Visit(expressions.WhereExpressions.First(), queryParameters));

                foreach (var whereExpression in expressions.WhereExpressions.Skip(1))
                {
                    queryBuilder.Append(" AND ")
                    .Append(QueryWhereClauseVisitor.Visit(whereExpression, queryParameters));
                }
            }

            if (expressions.GroupByExpression != null)
            {
                queryBuilder.Append(" ORDER BY ");

                queryBuilder.Append(
                    QueryOrderByClauseVisitor.Visit(expressions.GroupByExpression));
            }

            return(queryBuilder.ToString());
        }
            public static void CorrectlyHandlesGreaterThanComparisonOfDecimalProperty()
            {
                Expression <Func <Sale, bool> > whereFunc = x => x.Amount > 3m;

                var parameters = new Dictionary <string, object>();

                string actual = QueryWhereClauseVisitor.Visit(whereFunc, parameters);

                Assert.Equal("r.amount > @p1", actual);
                Assert.Single(parameters);
                Assert.Equal("@p1", parameters.Keys.First());
                Assert.Equal(3m, parameters["@p1"]);
            }