示例#1
0
        /// <summary>
        /// Gets the result kind of the <paramref name="serviceOperation"/>.
        /// </summary>
        /// <param name="serviceOperation">The <see cref="IEdmFunctionImport"/> to check.</param>
        /// <param name="model">The <see cref="IEdmModel"/> containing the annotation.</param>
        /// <returns>The result kind of the <paramref name="serviceOperation"/> or null if no result kind annotation exists.</returns>
        public static ODataServiceOperationResultKind?GetServiceOperationResultKind(this IEdmFunctionImport serviceOperation, IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(serviceOperation, "functionImport");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            ODataQueryEdmServiceOperationAnnotation annotation = model.GetAnnotationValue <ODataQueryEdmServiceOperationAnnotation>(serviceOperation);

            return(annotation == null ? null : (ODataServiceOperationResultKind?)annotation.ResultKind);
        }
示例#2
0
        /// <summary>
        /// Method that checks whether a function import is a service operation.
        /// </summary>
        /// <param name="functionImport">The <see cref="IEdmFunctionImport"/> to check.</param>
        /// <param name="model">The <see cref="IEdmModel"/> containing annotations.</param>
        /// <returns>true if the <paramref name="functionImport"/> represents a service operation; otherwise false.</returns>
        /// <remarks>
        /// A <see cref="IEdmFunctionImport"/> is considered a service operation if it has the
        /// <see cref="ODataQueryEdmServiceOperationAnnotation"/> annotation.
        /// </remarks>
        private static bool IsServiceOperation(IEdmFunctionImport functionImport, IEdmModel model)
        {
            Debug.Assert(functionImport != null, "functionImport != null");
            Debug.Assert(model != null, "model != null");

            // Check whether an annotation on the function import that makes it a service operation exists
            ODataQueryEdmServiceOperationAnnotation serviceOperationAnnotation = model.GetAnnotationValue <ODataQueryEdmServiceOperationAnnotation>(functionImport);

            return(serviceOperationAnnotation != null);
        }
示例#3
0
        /// <summary>
        /// Sets the result kind of the <paramref name="serviceOperation"/>.
        /// </summary>
        /// <param name="serviceOperation">The <see cref="IEdmFunctionImport"/> to check.</param>
        /// <param name="model">The <see cref="IEdmModel"/> containing the annotation.</param>
        /// <param name="resultKind">The result kind to set.</param>
        public static void SetServiceOperationResultKind(this IEdmFunctionImport serviceOperation, IEdmModel model, ODataServiceOperationResultKind resultKind)
        {
            ExceptionUtils.CheckArgumentNotNull(serviceOperation, "serviceOperation");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            ODataQueryEdmServiceOperationAnnotation existingAnnotation = model.GetAnnotationValue <ODataQueryEdmServiceOperationAnnotation>(serviceOperation);

            if (existingAnnotation == null)
            {
                ODataQueryEdmServiceOperationAnnotation newAnnotation =
                    new ODataQueryEdmServiceOperationAnnotation
                {
                    ResultKind = resultKind
                };
                model.SetAnnotationValue(serviceOperation, newAnnotation);
            }
            else
            {
                existingAnnotation.ResultKind = resultKind;
            }
        }