Exemple #1
0
        /// <summary>
        /// Invokes the Update method and gets the result.
        /// </summary>
        protected virtual object GetUpdateMethodResult(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            ModelDataSourceMethod method = EvaluateUpdateMethodParameters(keys, values, oldValues);
            ModelDataMethodResult result = InvokeMethod(method);

            return(result.ReturnValue);
        }
Exemple #2
0
        /// <summary>
        /// Invokes the Insert method and gets the result.
        /// </summary>
        protected virtual object GetInsertMethodResult(IDictionary values)
        {
            ModelDataSourceMethod method = EvaluateInsertMethodParameters(values);
            ModelDataMethodResult result = InvokeMethod(method);

            return(result.ReturnValue);
        }
Exemple #3
0
        /// <summary>
        /// Invokes the select method and gets the result. Also handles auto paging and sorting when required.
        /// </summary>
        /// <param name="arguments">The DataSourceSelectArguments for the select operation.
        /// When applicable, this method sets the TotalRowCount out parameter in the arguments.
        /// </param>
        /// <returns>The return value from the select method.</returns>
        protected virtual object GetSelectMethodResult(DataSourceSelectArguments arguments)
        {
            if (SelectMethod.Length == 0)
            {
                throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_SelectNotSupported));
            }

            DataSourceSelectResultProcessingOptions options = null;
            ModelDataSourceMethod method = EvaluateSelectMethodParameters(arguments, out options);
            ModelDataMethodResult result = InvokeMethod(method);

            return(ProcessSelectMethodResult(arguments, options, result));
        }
        /// <summary>
        /// This method performs operations on the select method result like auto paging and sorting if applicable.
        /// </summary>
        /// <param name="arguments">The DataSourceSelectArguments for the select operation.</param>
        /// <param name="selectResultProcessingOptions">The <see cref="System.Web.UI.WebControls.DataSourceSelectResultProcessingOptions"/> to use for processing the select result.
        /// These options are determined in an earlier call to <see cref="System.Web.UI.WebControls.ModelDataSourceView.EvaluateSelectMethodParameters"/>.
        /// </param>
        /// <param name="result">The result after operations like auto paging/sorting are done.</param>
        /// <returns></returns>
        protected virtual object ProcessSelectMethodResult(DataSourceSelectArguments arguments, DataSourceSelectResultProcessingOptions selectResultProcessingOptions, ModelDataMethodResult result) {
            // If the return value is null, there is no more processing to be done
            if (result.ReturnValue == null) {
                return null;
            }

            bool autoPage = selectResultProcessingOptions.AutoPage;
            bool autoSort = selectResultProcessingOptions.AutoSort;
            Type modelType = selectResultProcessingOptions.ModelType;
            string sortExpression = arguments.SortExpression;

            if (autoPage) {
                MethodInfo countHelperMethod = typeof(QueryableHelpers).GetMethod("CountHelper").MakeGenericMethod(modelType);
                arguments.TotalRowCount = (int)countHelperMethod.Invoke(null, new object[] { result.ReturnValue });

                //Bug 180907: We would like to auto sort on DataKeyName when paging is enabled and result is not already sorted by user to overcome a limitation in EF.
                MethodInfo isOrderingMethodFoundMethod = typeof(QueryableHelpers).GetMethod("IsOrderingMethodFound").MakeGenericMethod(modelType);
                bool isOrderingMethodFound = (bool)isOrderingMethodFoundMethod.Invoke(null, new object[] { result.ReturnValue });
                if (!isOrderingMethodFound) {
                    if (String.IsNullOrEmpty(sortExpression) && !String.IsNullOrEmpty(DataKeyName)) {
                        autoSort = true;
                        selectResultProcessingOptions.AutoSort = true;
                        sortExpression = DataKeyName;
                    }
                }
            }
            else if (arguments.StartRowIndex >= 0 && arguments.MaximumRows > 0) {
                //When paging is handled by developer, we need to set the TotalRowCount parameter from the select method out parameter.
                arguments.TotalRowCount = (int)result.OutputParameters[TotalRowCountParameterName];
            }

            if (autoPage || autoSort) {
                MethodInfo sortPageHelperMethod = typeof(QueryableHelpers).GetMethod("SortandPageHelper").MakeGenericMethod(modelType);
                object returnValue = sortPageHelperMethod.Invoke(null, new object[] { result.ReturnValue, 
                                                                                            autoPage ? (int?)arguments.StartRowIndex : null,
                                                                                            autoPage ? (int?)arguments.MaximumRows : null,
                                                                                            autoSort ? sortExpression : null });
                return returnValue;
            }

            return result.ReturnValue;
        }
Exemple #5
0
        /// <summary>
        /// This method performs operations on the select method result like auto paging and sorting if applicable.
        /// </summary>
        /// <param name="arguments">The DataSourceSelectArguments for the select operation.</param>
        /// <param name="selectResultProcessingOptions">The <see cref="System.Web.UI.WebControls.DataSourceSelectResultProcessingOptions"/> to use for processing the select result.
        /// These options are determined in an earlier call to <see cref="System.Web.UI.WebControls.ModelDataSourceView.EvaluateSelectMethodParameters"/>.
        /// </param>
        /// <param name="result">The result after operations like auto paging/sorting are done.</param>
        /// <returns></returns>
        protected virtual object ProcessSelectMethodResult(DataSourceSelectArguments arguments, DataSourceSelectResultProcessingOptions selectResultProcessingOptions, ModelDataMethodResult result)
        {
            // If the return value is null, there is no more processing to be done
            if (result.ReturnValue == null)
            {
                return(null);
            }

            bool   autoPage       = selectResultProcessingOptions.AutoPage;
            bool   autoSort       = selectResultProcessingOptions.AutoSort;
            Type   modelType      = selectResultProcessingOptions.ModelType;
            string sortExpression = arguments.SortExpression;

            if (autoPage)
            {
                MethodInfo countHelperMethod = typeof(QueryableHelpers).GetMethod("CountHelper").MakeGenericMethod(modelType);
                arguments.TotalRowCount = (int)countHelperMethod.Invoke(null, new object[] { result.ReturnValue });

                //Bug 180907: We would like to auto sort on DataKeyName when paging is enabled and result is not already sorted by user to overcome a limitation in EF.
                MethodInfo isOrderingMethodFoundMethod = typeof(QueryableHelpers).GetMethod("IsOrderingMethodFound").MakeGenericMethod(modelType);
                bool       isOrderingMethodFound       = (bool)isOrderingMethodFoundMethod.Invoke(null, new object[] { result.ReturnValue });
                if (!isOrderingMethodFound)
                {
                    if (String.IsNullOrEmpty(sortExpression) && !String.IsNullOrEmpty(DataKeyName))
                    {
                        autoSort = true;
                        selectResultProcessingOptions.AutoSort = true;
                        sortExpression = DataKeyName;
                    }
                }
            }
            else if (arguments.StartRowIndex >= 0 && arguments.MaximumRows > 0)
            {
                //When paging is handled by developer, we need to set the TotalRowCount parameter from the select method out parameter.
                arguments.TotalRowCount = (int)result.OutputParameters[TotalRowCountParameterName];
            }

            if (autoPage || autoSort)
            {
                MethodInfo sortPageHelperMethod = typeof(QueryableHelpers).GetMethod("SortandPageHelper").MakeGenericMethod(modelType);
                object     returnValue          = sortPageHelperMethod.Invoke(null, new object[] { result.ReturnValue,
                                                                                                   autoPage ? (int?)arguments.StartRowIndex : null,
                                                                                                   autoPage ? (int?)arguments.MaximumRows : null,
                                                                                                   autoSort ? sortExpression : null });
                return(returnValue);
            }

            return(result.ReturnValue);
        }