Пример #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");
        }
Пример #2
0
        public Db.OeAsyncEnumerator GetAsyncEnumerator(ODataUri odataUri, Stream requestStream, OeRequestHeaders headers, Object dataContext, out bool isScalar)
        {
            isScalar = true;
            var importSegment = (OperationImportSegment)odataUri.Path.LastSegment;
            IReadOnlyList<KeyValuePair<String, Object>> parameters = OeOperationHelper.GetParameters(_edmModel, importSegment, odataUri.ParameterAliasNodes, requestStream, headers.ContentType);

            IEdmOperationImport operationImport = importSegment.OperationImports.Single();
            IEdmEntitySet entitySet = OeOperationHelper.GetEntitySet(operationImport);
            if (entitySet == null)
            {
                if (operationImport.Operation.ReturnType == null)
                    return _dataAdapter.OperationAdapter.ExecuteProcedureNonQuery(dataContext, operationImport.Name, parameters);

                Type returnType = _edmModel.GetClrType(operationImport.Operation.ReturnType.Definition);
                if (operationImport.Operation.ReturnType.IsCollection())
                {
                    isScalar = false;
                    returnType = typeof(IEnumerable<>).MakeGenericType(returnType);
                }

                if (_edmModel.IsDbFunction(operationImport.Operation))
                    return _dataAdapter.OperationAdapter.ExecuteFunctionPrimitive(dataContext, operationImport.Name, parameters, returnType);
                else
                    return _dataAdapter.OperationAdapter.ExecuteProcedurePrimitive(dataContext, operationImport.Name, parameters, returnType);
            }

            isScalar = false;
            Db.OeEntitySetAdapter entitySetAdapter = _dataAdapter.EntitySetAdapters.Find(entitySet);
            if (_edmModel.IsDbFunction(operationImport.Operation))
                return _dataAdapter.OperationAdapter.ExecuteFunctionReader(dataContext, operationImport.Name, parameters, entitySetAdapter);
            else
                return _dataAdapter.OperationAdapter.ExecuteProcedureReader(dataContext, operationImport.Name, parameters, entitySetAdapter);
        }