internal string CreateN1QlQuery(IBucket bucket, Expression expression, ClusterVersion clusterVersion,
                                        bool selectDocumentMetadata, out ScalarResultBehavior resultBehavior)
        {
            var serializer = new Core.Serialization.DefaultSerializer();

            var bucketContext = new Mock <IBucketContext>();

            bucketContext.SetupGet(p => p.Bucket).Returns(bucket);
            bucketContext.SetupGet(p => p.Configuration).Returns(new ClientConfiguration
            {
                Serializer = () => serializer
            });

            var queryModel = QueryParserHelper.CreateQueryParser(bucketContext.Object).GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer             = serializer,
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = clusterVersion
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);

            resultBehavior = visitor.ScalarResultBehavior;
            return(visitor.GetQuery());
        }
示例#2
0
        internal string CreateN1QlQuery(IBucket bucket, Expression expression, ClusterVersion clusterVersion,
                                        bool selectDocumentMetadata, out ScalarResultBehavior resultBehavior)
        {
            var mockCluster = new Mock <ICluster>();

            mockCluster
            .Setup(p => p.ClusterServices)
            .Returns(ServiceProvider);

            var queryModel = QueryParserHelper.CreateQueryParser(mockCluster.Object).GetParsedQuery(expression);

            var queryGenerationContext = new N1QlQueryGenerationContext()
            {
                MemberNameResolver           = MemberNameResolver,
                MethodCallTranslatorProvider = new DefaultMethodCallTranslatorProvider(),
                Serializer             = ServiceProvider.GetRequiredService <ITypeSerializer>(),
                SelectDocumentMetadata = selectDocumentMetadata,
                ClusterVersion         = clusterVersion,
                LoggerFactory          = LoggerFactory
            };

            var visitor = new N1QlQueryModelVisitor(queryGenerationContext);

            visitor.VisitQueryModel(queryModel);

            resultBehavior = visitor.ScalarResultBehavior;
            return(visitor.GetQuery());
        }
        /// <summary>
        /// Creates a new LinqQueryRequest, with the given N1QL query.
        /// </summary>
        /// <param name="query">N1QL query.</param>
        /// <param name="scalarResultBehavior">Behaviors related to extracting results for scalar queries.</param>
        public LinqQueryRequest(string query, ScalarResultBehavior scalarResultBehavior)
            : base(query)
        {
            if (scalarResultBehavior == null)
            {
                throw new ArgumentNullException("scalarResultBehavior");
            }

            _scalarResultBehavior = scalarResultBehavior;
        }
示例#4
0
 /// <summary>
 /// Creates a new LinqQueryRequest, with the given N1QL query.
 /// </summary>
 /// <param name="scalarResultBehavior">Behaviors related to extracting results for scalar queries.</param>
 public LinqQueryOptions(ScalarResultBehavior scalarResultBehavior)
 {
     _scalarResultBehavior = scalarResultBehavior ?? throw new ArgumentNullException("scalarResultBehavior");
 }