示例#1
0
        /// <summary>
        /// Generate document db sql query that
        /// queries a set of items
        /// with "where" clause generated from odata query in queryOptions object.
        /// </summary>
        /// <returns>the generated docdb sql query in a string.
        /// The generated query is logged in applicatio insight as a trace event.</returns>
        public string TranslateToDocDBQuery <T>(ODataQueryOptions <T> queryOptions) where T : class
        {
            string query;

            if (queryOptions.Filter != null)
            {
                WhereAndJoinClause where = TranslateODataFilterToDocDBWhereAndJoin(queryOptions.Filter);
                string ItemTypeFilterClause = string.Empty;

                if (where.JoinClause.Any())
                {
                    string j = string.Empty;
                    foreach (var str in where.JoinClause)
                    {
                        j += str + " ";
                    }

                    query = string.Format("SELECT c FROM c {0} WHERE {2} ({1})", j, where.Clause, ItemTypeFilterClause);
                }
                else
                {
                    query = string.Format("SELECT c FROM c WHERE {1} ({0})", where.Clause, ItemTypeFilterClause);
                }
            }
            else
            {
                query = string.Format("SELECT c FROM c");
            }
            return(query);
        }
示例#2
0
        /// <summary>
        /// translate an odata filter clause to a documentdb where and self join clause.
        /// </summary>
        /// <param name="filterQuery">odata filter option object which contains a AST of odata filter clause</param>
        /// <returns>WhereAndJoinClause object that contains the where clause and a list of self join clauses.
        /// if filterQuery is null, it will return an empty where clause and an empty list of self join clauses.</returns>
        public WhereAndJoinClause TranslateODataFilterToDocDBWhereAndJoin(FilterQueryOption filterQuery)
        {
            whereAndJoinClause = new WhereAndJoinClause
            {
                Clause     = String.Empty,
                JoinClause = new List <string>()
            };

            RangeVariablesNameForAnyNodeBody = new Stack <string>();

            if (filterQuery != null)
            {
                if (filterQuery.FilterClause != null && filterQuery.FilterClause.Expression != null)
                {
                    whereAndJoinClause.Clause = Translate(filterQuery.FilterClause.Expression);
                    // JoinClause will be filled in by TranslateFilter through the static instance whereAndJoinClause
                }
            }

            return(whereAndJoinClause);
        }
示例#3
0
 public DocDBQueryGenerator()
 {
     whereAndJoinClause = null;
 }