Exemple #1
0
        public void AddWrappingFunction(string function)
        {
            if (WrappingFunctions == null)
            {
                WrappingFunctions = new List <string>();
            }

            WrappingFunctions.Add(function);
        }
Exemple #2
0
        /// <summary>
        /// Build a subquery against a nested array property
        /// </summary>
        /// <returns></returns>
        private string BuildArrayQuery()
        {
            var sb = new StringBuilder();

            var mainFrom = FromParts.FirstOrDefault();

            if (mainFrom == null)
            {
                throw new InvalidOperationException("N1QL Subquery Missing From Part");
            }

            if (WrappingFunctions != null)
            {
                foreach (string function in WrappingFunctions.AsEnumerable().Reverse())
                {
                    sb.AppendFormat("{0}(", function);
                }
            }

            if ((SelectPart != mainFrom.ItemName) || WhereParts.Any())
            {
                sb.AppendFormat("ARRAY {0} FOR {1} IN {2}", SelectPart, mainFrom.ItemName, mainFrom.Source);

                if (WhereParts.Any())
                {
                    sb.AppendFormat(" WHEN {0}", String.Join(" AND ", WhereParts));
                }

                sb.Append(" END");
            }
            else
            {
                // has no projection or predicates, so simplify

                sb.Append(mainFrom.Source);
            }

            if (WrappingFunctions != null)
            {
                sb.Append(')', WrappingFunctions.Count);
            }

            return(sb.ToString());
        }