public string GenerateQuery(QueryModel queryModel, out ScalarResultBehavior scalarResultBehavior)
        {
            // If ITypeSerializer is an IExtendedTypeSerializer, use it as the member name resolver
            // Otherwise fallback to the legacy behavior which assumes we're using Newtonsoft.Json
            // Note that DefaultSerializer implements IExtendedTypeSerializer, but has the same logic as JsonNetMemberNameResolver

            var serializer = Serializer as IExtendedTypeSerializer;

#pragma warning disable CS0618 // Type or member is obsolete
            var memberNameResolver = serializer != null ?
                                     (IMemberNameResolver) new ExtendedTypeSerializerMemberNameResolver(serializer) :
                                     (IMemberNameResolver) new JsonNetMemberNameResolver(JsonConvert.DefaultSettings().ContractResolver);
#pragma warning restore CS0618 // Type or member is obsolete

            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();

            var queryGenerationContext = new N1QlQueryGenerationContext
            {
                MemberNameResolver           = memberNameResolver,
                MethodCallTranslatorProvider = methodCallTranslatorProvider,
                Serializer = serializer,
                // TODO: Don't use .Result
                ClusterVersion = _clusterVersionProvider.GetVersionAsync().Result ?? FeatureVersions.DefaultVersion,
                LoggerFactory  = _cluster.ClusterServices.GetRequiredService <ILoggerFactory>()
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);
            visitor.VisitQueryModel(queryModel);

            var query = visitor.GetQuery();
            _logger.LogDebug("Generated query: {0}", query);

            scalarResultBehavior = visitor.ScalarResultBehavior;
            return(query);
        }
        private LinqQueryOptions GetQueryOptions(QueryModel queryModel, ScalarResultBehavior scalarResultBehavior)
        {
            var queryOptions = new LinqQueryOptions(scalarResultBehavior);

            MutationState?combinedMutationState = null;

            foreach (var bodyClause in queryModel.BodyClauses)
            {
                switch (bodyClause)
                {
                case ScanConsistencyClause scanConsistency:
                    queryOptions.ScanConsistency(scanConsistency.ScanConsistency);

                    if (scanConsistency.ScanWait != null)
                    {
                        queryOptions.ScanWait(scanConsistency.ScanWait.Value);
                    }
                    break;

                case ConsistentWithClause consistentWith:
                    combinedMutationState ??= new MutationState();
                    combinedMutationState.Add(consistentWith.MutationState);

                    if (consistentWith.ScanWait != null)
                    {
                        queryOptions.ScanWait(consistentWith.ScanWait.Value);
                    }
                    break;
                }
            }

            if (combinedMutationState != null)
            {
                queryOptions.ConsistentWith(combinedMutationState);
            }

            if (QueryTimeout != null)
            {
                queryOptions.Timeout(QueryTimeout.Value);
            }

            return(queryOptions);
        }
        public string GenerateQuery(QueryModel queryModel, bool selectDocumentMetadata, out ScalarResultBehavior scalarResultBehavior)
        {
            // If ITypeSerializer is an IExtendedTypeSerializer, use it as the member name resolver
            // Otherwise fallback to the legacy behavior which assumes we're using Newtonsoft.Json
            // Note that DefaultSerializer implements IExtendedTypeSerializer, but has the same logic as JsonNetMemberNameResolver

            var serializer = Serializer as IExtendedTypeSerializer;

#pragma warning disable CS0618 // Type or member is obsolete
            var memberNameResolver = serializer != null ?
                                     (IMemberNameResolver) new ExtendedTypeSerializerMemberNameResolver(serializer) :
                                     (IMemberNameResolver) new JsonNetMemberNameResolver(_configuration.SerializationSettings.ContractResolver);
#pragma warning restore CS0618 // Type or member is obsolete

            var methodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider();

            var queryGenerationContext = new N1QlQueryGenerationContext
            {
                MemberNameResolver           = memberNameResolver,
                MethodCallTranslatorProvider = methodCallTranslatorProvider,
                Serializer             = serializer,
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = VersionProvider.Current.GetVersion(_bucket)
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);
            visitor.VisitQueryModel(queryModel);

            var query = visitor.GetQuery();
            _log.Debug("Generated query: {0}", query);

            scalarResultBehavior = visitor.ScalarResultBehavior;
            return(query);
        }