public CosmosLinqQuery( ContainerInternal container, CosmosResponseFactoryInternal responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, Expression expression, bool allowSynchronousQueryExecution, CosmosLinqSerializerOptions linqSerializationOptions = null) { this.container = container ?? throw new ArgumentNullException(nameof(container)); this.responseFactory = responseFactory ?? throw new ArgumentNullException(nameof(responseFactory)); this.queryClient = queryClient ?? throw new ArgumentNullException(nameof(queryClient)); this.continuationToken = continuationToken; this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.Expression = expression ?? Expression.Constant(this); this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.correlatedActivityId = Guid.NewGuid(); this.linqSerializationOptions = linqSerializationOptions; this.queryProvider = new CosmosLinqQueryProvider( container, responseFactory, queryClient, this.continuationToken, cosmosQueryRequestOptions, this.allowSynchronousQueryExecution, this.queryClient.OnExecuteScalarQueryCallback, this.linqSerializationOptions); }
internal static string TranslateExpressionOld( Expression inputExpression, CosmosLinqSerializerOptions linqSerializerOptions = null) { TranslationContext context = new TranslationContext(linqSerializerOptions); inputExpression = ConstantFolding.Fold(inputExpression); SqlScalarExpression scalarExpression = ExpressionToSql.VisitNonSubqueryScalarExpression(inputExpression, context); return(scalarExpression.ToString()); }
public override IOrderedQueryable <T> GetItemLinqQueryable <T>( bool allowSynchronousQueryExecution = false, string continuationToken = null, QueryRequestOptions requestOptions = null, CosmosLinqSerializerOptions linqSerializerOptions = null) { return(this.container.GetItemLinqQueryable <T>( allowSynchronousQueryExecution, continuationToken, requestOptions, linqSerializerOptions)); }
public TranslationContext(CosmosLinqSerializerOptions linqSerializerOptions, IDictionary <object, string> parameters = null) { this.InScope = new HashSet <ParameterExpression>(); this.substitutions = new ParameterSubstitution(); this.methodStack = new List <MethodCallExpression>(); this.lambdaParametersStack = new List <ParameterExpression>(); this.collectionStack = new List <Collection>(); this.currentQuery = new QueryUnderConstruction(this.GetGenFreshParameterFunc()); this.subqueryBindingStack = new Stack <SubqueryBinding>(); this.linqSerializerOptions = linqSerializerOptions; this.parameters = parameters; this.memberNames = new MemberNames(linqSerializerOptions); }
public CosmosLinqQuery( ContainerInternal container, CosmosResponseFactoryInternal responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution, CosmosLinqSerializerOptions linqSerializerOptions = null) : this( container, responseFactory, queryClient, continuationToken, cosmosQueryRequestOptions, null, allowSynchronousQueryExecution, linqSerializerOptions) { }
public CosmosLinqQueryProvider( ContainerInternal container, CosmosResponseFactoryInternal responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution, Action <IQueryable> onExecuteScalarQueryCallback = null, CosmosLinqSerializerOptions linqSerializerOptions = null) { this.container = container; this.responseFactory = responseFactory; this.queryClient = queryClient; this.continuationToken = continuationToken; this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.onExecuteScalarQueryCallback = onExecuteScalarQueryCallback; this.linqSerializerOptions = linqSerializerOptions; }
private static SqlQuerySpec HandleMethodCallExpression( MethodCallExpression expression, IDictionary <object, string> parameters, CosmosLinqSerializerOptions linqSerializerOptions = null) { if (DocumentQueryEvaluator.IsTransformExpression(expression)) { if (string.Compare(expression.Method.Name, DocumentQueryEvaluator.SQLMethod, StringComparison.Ordinal) == 0) { return(DocumentQueryEvaluator.HandleAsSqlTransformExpression(expression)); } else { throw new DocumentQueryException( string.Format(CultureInfo.CurrentUICulture, ClientResources.BadQuery_InvalidExpression, expression.ToString())); } } return(SqlTranslator.TranslateQuery(expression, linqSerializerOptions, parameters)); }
internal static SqlQuerySpec TranslateQuery( Expression inputExpression, CosmosLinqSerializerOptions linqSerializerOptions, IDictionary <object, string> parameters) { inputExpression = ConstantEvaluator.PartialEval(inputExpression); SqlQuery query = ExpressionToSql.TranslateQuery(inputExpression, parameters, linqSerializerOptions); string queryText = null; SqlParameterCollection sqlParameters = new SqlParameterCollection(); if (parameters != null && parameters.Count > 0) { foreach (KeyValuePair <object, string> keyValuePair in parameters) { sqlParameters.Add(new Microsoft.Azure.Cosmos.Query.Core.SqlParameter(keyValuePair.Value, keyValuePair.Key)); } } queryText = query.ToString(); SqlQuerySpec sqlQuerySpec = new SqlQuerySpec(queryText, sqlParameters); return(sqlQuerySpec); }
public static string GetMemberName(this MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null) { string memberName = null; // Json.Net honors JsonPropertyAttribute more than DataMemberAttribute // So we check for JsonPropertyAttribute first. JsonPropertyAttribute jsonPropertyAttribute = memberInfo.GetCustomAttribute <JsonPropertyAttribute>(true); if (jsonPropertyAttribute != null && !string.IsNullOrEmpty(jsonPropertyAttribute.PropertyName)) { memberName = jsonPropertyAttribute.PropertyName; } else { DataContractAttribute dataContractAttribute = memberInfo.DeclaringType.GetCustomAttribute <DataContractAttribute>(true); if (dataContractAttribute != null) { DataMemberAttribute dataMemberAttribute = memberInfo.GetCustomAttribute <DataMemberAttribute>(true); if (dataMemberAttribute != null && !string.IsNullOrEmpty(dataMemberAttribute.Name)) { memberName = dataMemberAttribute.Name; } } } if (memberName == null) { memberName = memberInfo.Name; } if (linqSerializerOptions != null) { memberName = CosmosSerializationUtil.GetStringWithPropertyNamingPolicy(linqSerializerOptions, memberName); } return(memberName); }
public static SqlQuerySpec Evaluate( Expression expression, CosmosLinqSerializerOptions linqSerializerOptions = null, IDictionary <object, string> parameters = null) { switch (expression.NodeType) { case ExpressionType.Constant: { return(DocumentQueryEvaluator.HandleEmptyQuery((ConstantExpression)expression)); } case ExpressionType.Call: { return(DocumentQueryEvaluator.HandleMethodCallExpression((MethodCallExpression)expression, parameters, linqSerializerOptions)); } default: throw new DocumentQueryException( string.Format(CultureInfo.CurrentUICulture, ClientResources.BadQuery_InvalidExpression, expression.ToString())); } }
internal MemberNames(CosmosLinqSerializerOptions options) { this.Value = CosmosSerializationUtil.GetStringWithPropertyNamingPolicy(options, nameof(this.Value)); this.HasValue = CosmosSerializationUtil.GetStringWithPropertyNamingPolicy(options, nameof(this.HasValue)); }
public override IOrderedQueryable <T> GetItemLinqQueryable <T>(bool allowSynchronousQueryExecution = false, string continuationToken = null, QueryRequestOptions requestOptions = null, CosmosLinqSerializerOptions linqSerializerOptions = null) => throw new NotImplementedException();
public TranslationContext(CosmosLinqSerializerOptions linqSerializerOptions, IDictionary <object, string> parameters = null) : this() { this.linqSerializerOptions = linqSerializerOptions; this.parameters = parameters; }