예제 #1
0
 /// <summary>
 /// Get the command wrapper, either from the stored procedures or from the embedded queries.
 /// </summary>
 /// <param name="database">The database instance.</param>
 /// <param name="commandName">the name of the sp.</param>
 /// <param name="useStoredProcedure">Indicates if we want stored procedure.</param>
 /// <returns></returns>
 public static DbCommand GetCommandWrapper(Database database, string commandName, bool useStoredProcedure)
 {
     if (useStoredProcedure)
     {
         DbCommand command = database.GetStoredProcCommand(commandName);
         command.CommandTimeout = DataRepository.Provider.DefaultCommandTimeout;
         return(command);
     }
     else
     {
         DbCommand command =
             database.GetSqlStringCommand(StoredProcedureProvider.GetProcedureBodyFromEmbeddedResource(commandName));
         command.CommandTimeout = DataRepository.Provider.DefaultCommandTimeout;
         return(command);
     }
 }
예제 #2
0
        /// <summary>
        /// Gets the command wrapper for a dynamically generated query and
        /// optionally includes server-side paging.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="commandName"></param>
        /// <param name="columnEnum"></param>
        /// <param name="parameters"></param>
        /// <param name="orderBy"></param>
        /// <param name="start"></param>
        /// <param name="pageLength"></param>
        /// <returns></returns>
        public static DbCommand GetCommandWrapper(Database database, String commandName, Type columnEnum, SqlFilterParameterCollection parameters, String orderBy, int start, int pageLength)
        {
            String query = StoredProcedureProvider.GetProcedureBodyFromEmbeddedResource(commandName);
            //query = query.Replace(SqlUtil.PAGE_INDEX, string.Concat(SqlUtil.PAGE_INDEX, Guid.NewGuid().ToString("N").Substring(0,8)));
            String sortExpression = Utility.ParseSortExpression(columnEnum, orderBy);
            String whereClause    = String.Empty;

            if (parameters != null && !String.IsNullOrEmpty(parameters.FilterExpression))
            {
                whereClause = String.Format("where {0}", parameters.FilterExpression);
            }

            // replace dynamic components
            query = String.Format(query, whereClause, sortExpression, start, (start + pageLength));

            DbCommand command = database.GetSqlStringCommand(query);

            command.CommandTimeout = DataRepository.Provider.DefaultCommandTimeout;
            return(command);
        }