Пример #1
0
        /// <summary>
        /// Composes and executes the query asynchronously based on the <see cref="RemoteLinq.Expression"/> and maps the result into dynamic objects.
        /// </summary>
        /// <remarks>
        /// Multiple active operations on the same EF context instance are not supported. Use 'await' to ensure
        /// that any asynchronous operations have completed before calling another method on the same context.
        /// </remarks>
        /// <param name="expression">The <see cref="RemoteLinq.Expression"/> to be executed.</param>
        /// <param name="cancellation">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// The task result contains the mapped result of the query execution.
        /// </returns>
        public async ValueTask <TDataTranferObject> ExecuteAsync(RemoteLinq.Expression expression, CancellationToken cancellation = default)
        {
            expression.AssertNotNull(nameof(expression));

            var ctx = Context;

            var preparedRemoteExpression = Prepare(expression);

            ctx.RemoteExpression = preparedRemoteExpression;

            var linqExpression = Transform(preparedRemoteExpression);

            var preparedLinqExpression = PrepareAsyncQuery(linqExpression, cancellation);

            ctx.SystemExpression = preparedLinqExpression;

            var queryResult = await ExecuteAsync(preparedLinqExpression, cancellation).ConfigureAwait(false);

            var processedResult = ProcessResult(queryResult);

            var dynamicObjects = ConvertResult(processedResult);

            var processedDynamicObjects = ProcessResult(dynamicObjects);

            return(processedDynamicObjects);
        }
Пример #2
0
        private static IQueryable <T1> BuildQuery <T1, T2>(IQueryable <T1> queriable1, IQueryable <T2> queriable2)
            where T1 : IValue
            where T2 : IValue
        {
            Expression <Func <T2, bool> > subfilter =
                x => x.Value % 2 == 0;

            Expression <Func <T1, bool> > outerfilter =
                x => queriable2.Where(subfilter).Where(d => d.Value == x.Value).Any();

            return(queriable1.Where(outerfilter));
        }
Пример #3
0
        /// <summary>
        /// Composes and executes the query based on the <see cref="RemoteLinq.Expression"/>.
        /// </summary>
        /// <param name="expression">The <see cref="RemoteLinq.Expression"/> to be executed.</param>
        /// <param name="cancellation">A <see cref="CancellationToken" /> to observe while waiting for the async operation to complete.</param>
        /// <returns>The mapped result of the query execution.</returns>
        public IAsyncEnumerable <TDataTranferObject> ExecuteAsyncStream(RemoteLinq.Expression expression, CancellationToken cancellation = default)
        {
            var ctx = Context;

            var preparedRemoteExpression = Prepare(expression);

            ctx.RemoteExpression = preparedRemoteExpression;

            var linqExpression = Transform(preparedRemoteExpression);

            var preparedLinqExpression = Prepare(linqExpression);

            ctx.SystemExpression = preparedLinqExpression;

            var queryResult = ExecuteAsyncStream(preparedLinqExpression, cancellation);

            var processedResult = ProcessResult(queryResult);

            var dataTransferObjects = ConvertResult(processedResult);

            var processedDataTransferObjects = ProcessResult(dataTransferObjects);

            return(processedDataTransferObjects);
        }
Пример #4
0
        /// <summary>
        /// Composes and executes the query based on the <see cref="RemoteLinq.Expression"/> and maps the result into dynamic objects.
        /// </summary>
        /// <param name="expression">The <see cref="RemoteLinq.Expression"/> to be executed.</param>
        /// <returns>The mapped result of the query execution.</returns>
        public TDataTranferObject Execute(RemoteLinq.Expression expression)
        {
            var ctx = Context;

            var preparedRemoteExpression = Prepare(expression);

            ctx.RemoteExpression = preparedRemoteExpression;

            var linqExpression = Transform(preparedRemoteExpression);

            var preparedLinqExpression = Prepare(linqExpression);

            ctx.SystemExpression = preparedLinqExpression;

            var queryResult = Execute(preparedLinqExpression);

            var processedResult = ProcessResult(queryResult);

            var dataTransferObjects = ConvertResult(processedResult);

            var processedDataTransferObjects = ProcessResult(dataTransferObjects);

            return(processedDataTransferObjects);
        }
 public SystemLinq.Expression ToExpression(RemoteLinq.Expression expression) => Visit(expression.CheckNotNull(nameof(expression)));
Пример #6
0
 /// <summary>
 /// Transforms the <see cref="RemoteLinq.Expression"/> to a <see cref="SystemLinq.Expression"/>.
 /// </summary>
 /// <param name="expression">The <see cref="RemoteLinq.Expression"/> to be transformed.</param>
 /// <returns>A <see cref="SystemLinq.Expression"/>.</returns>
 protected virtual SystemLinq.Expression Transform(RemoteLinq.Expression expression)
 => expression.ToLinqExpression(_context);
Пример #7
0
 /// <summary>
 /// Prepares the <see cref="RemoteLinq.Expression"/> befor being transformed.<para/>
 /// </summary>
 /// <param name="expression">The <see cref="RemoteLinq.Expression"/>.</param>
 /// <returns>A <see cref="SystemLinq.Expression"/>.</returns>
 protected virtual RemoteLinq.Expression Prepare(RemoteLinq.Expression expression)
 => expression
 .ReplaceNonGenericQueryArgumentsByGenericArguments()
 .ReplaceResourceDescriptorsByQueryable(_queryableProvider, _context.TypeResolver);
Пример #8
0
 SystemLinq.Expression IAsyncStreamExpressionExecutionDecorator <TDataTranferObject> .Transform(RemoteLinq.Expression expression)
 => Transform(expression);
Пример #9
0
 RemoteLinq.Expression IAsyncStreamExpressionExecutionDecorator <TDataTranferObject> .Prepare(RemoteLinq.Expression expression)
 => Prepare(expression);
Пример #10
0
 protected override RemoteLinq.Expression Prepare(RemoteLinq.Expression expression)
 => _transform(base.Prepare(expression));
 protected override RemoteLinq.Expression Prepare(RemoteLinq.Expression expression)
 => base.Prepare(expression)
 .MapIncludeQueryMethods();
Пример #12
0
 public static SystemLinq.Expression ToLinqExpression(this RemoteLinq.Expression expression, ITypeResolver?typeResolver)
 => ToLinqExpression(expression, GetExpressionTranslatorContextOrNull(typeResolver));
Пример #13
0
 /// <summary>
 /// Translates a given remote linq expression into an system linq expression.
 /// </summary>
 public static SystemLinq.Expression ToLinqExpression(this RemoteLinq.Expression expression, IExpressionFromRemoteLinqContext?context = null)
 => new RemoteToSystemLinqTranslator(context ?? ExpressionTranslatorContext.Default).ToExpression(expression);
Пример #14
0
 public ResultWrapperExpression(RemoteLinq.Expression result, Type type)
 {
     Result = result;
     Type   = type;
 }