Exemple #1
0
        public static Db.OeAsyncEnumerator ApplyBoundFunction(OeQueryContext queryContext)
        {
            if (queryContext.ODataUri.Path.LastSegment is OperationSegment operationSegment)
            {
                var        edmFunction = (IEdmFunction)operationSegment.Operations.First();
                MethodInfo methodInfo  = queryContext.EdmModel.GetMethodInfo(edmFunction);

                IReadOnlyList <KeyValuePair <String, Object> > parameterList = OeOperationHelper.GetParameters(
                    queryContext.EdmModel, operationSegment, queryContext.ODataUri.ParameterAliasNodes);

                Db.OeBoundFunctionParameter boundFunctionParameter = OeOperationHelper.CreateBoundFunctionParameter(queryContext);

                var parameters = new Object[parameterList.Count + 1];
                parameters[0] = boundFunctionParameter;
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = parameterList[i - 1].Value;
                }

                Object result = methodInfo.Invoke(null, parameters);
                queryContext.EntryFactory = boundFunctionParameter.CreateEntryFactory();
                if (result is IEnumerable enumerable)
                {
                    return(new Db.OeAsyncEnumeratorAdapter(enumerable, CancellationToken.None));
                }

                return(new Db.OeScalarAsyncEnumeratorAdapter(Task.FromResult(result), CancellationToken.None));
            }

            throw new InvalidOperationException("Path last segment not OperationSegment");
        }
        public static IEnumerable <Order> BoundFunction(Db.OeBoundFunctionParameter <Customer, Order> boundParameter, IEnumerable <String> orderNames)
        {
            OrderContext orderContext = boundParameter.CreateDataContext <OrderContext>();

            IQueryable <Customer> customers = boundParameter.ApplyFilter(orderContext.Customers, orderContext);
            IQueryable <Order>    orders    = customers.SelectMany(c => c.Orders).Where(o => orderNames.Contains(o.Name));
            IQueryable            result    = boundParameter.ApplySelect(orders, orderContext);
            List <Order>          orderList = boundParameter.Materialize(result).ToList().GetAwaiter().GetResult();

            boundParameter.CloseDataContext(orderContext);
            return(orderList);
        }
Exemple #3
0
        public static IEnumerable <Order> BoundFunction(Db.OeBoundFunctionParameter <Customer, Order> boundParameter, IEnumerable <String> orderNames)
        {
            using (var orderContext = new OdataToEntityDB())
            {
                IQueryable <Customer> customers = boundParameter.ApplyFilter(orderContext.Customers, orderContext);
                IQueryable <Order>    orders    = customers.SelectMany(c => c.Orders).Where(o => orderNames.Contains(o.Name));

                IQueryable   result    = boundParameter.ApplySelect(orders, orderContext);
                List <Order> orderList = boundParameter.Materialize(result).ToListAsync().GetAwaiter().GetResult();
                return(orderList);
            }
        }