Пример #1
0
        /// <summary>
        /// Executes the stored procedure with the given name, passes the provided parameters and used the generateMethod to return an instance of the passed generic type. You can pass optional filter parameters which are passed to the generateMethod
        /// </summary>
        /// <typeparam name="ClassName">The type of the class to return.</typeparam>
        /// <param name="storedProcedureName">Name of the stored procedure.</param>
        /// <param name="generateMethod">The method expecting a DataRow and return an instance of the passed generic type.</param>
        /// <param name="filterParameters">The filter parameters.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>An instance of the passed generic type</returns>
        public ClassName ExecuteClassQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, object[] filterParameters, Dictionary <string, object> parameters)
        {
            if (parameters == null)
            {
                parameters = new Dictionary <string, object>();
            }

            SqlDataReader reader = ExecuteReader(storedProcedureName, parameters);

            if (reader.Read())
            {
                ClassName result = generateMethod(reader, filterParameters);
                DoPostCommandProcessing();
                return(result);
            }

            return(default(ClassName));
        }
Пример #2
0
 public List <ClassName> ExecuteClassListQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, object[] filterParameters)
 {
     return(ExecuteClassListQuery(storedProcedureName, generateMethod, filterParameters, (object[])null));
 }
Пример #3
0
        public PagedList <ClassName> ExecutePagedClassListQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, int?startIndex, int?endIndex, object[] filterParameters, Dictionary <string, object> parameters)
        {
            if (parameters == null)
            {
                parameters = new Dictionary <string, object>();
            }

            SqlParameter virtualCountParameter = new SqlParameter("@VirtualCount", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            SqlParameter startIndexParameter = new SqlParameter("@StartIndex", startIndex == null ? DBNull.Value : (object)startIndex.Value);
            SqlParameter endIndexParameter   = new SqlParameter("@EndIndex", endIndex == null ? DBNull.Value : (object)endIndex.Value);

            SqlParameterCollection outputParameters;
            SqlDataReader          reader = ExecuteReader(storedProcedureName, parameters, new[] { startIndexParameter, endIndexParameter, virtualCountParameter }, out outputParameters);

            PagedList <ClassName> result = new PagedList <ClassName> {
                VirtualCount = Convert.ToInt32(outputParameters["@VirtualCount"])
            };

            while (reader.Read())
            {
                result.Add(generateMethod(reader, filterParameters));
            }

            DoPostCommandProcessing();

            return(result);
        }
Пример #4
0
 public PagedList <ClassName> ExecutePagedClassListQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, int?startIndex, int?endIndex, object[] filterParameters, params object[] parameters)
 {
     return(ExecutePagedClassListQuery(storedProcedureName, generateMethod, startIndex, endIndex, filterParameters, GetParametersFromObjectArray(parameters)));
 }
Пример #5
0
        public List <ClassName> ExecuteClassListQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, object[] filterParameters, Dictionary <string, object> parameters)
        {
            if (parameters == null)
            {
                parameters = new Dictionary <string, object>();
            }

            SqlDataReader    reader = ExecuteReader(storedProcedureName, parameters);
            List <ClassName> result = new List <ClassName>();

            while (reader.Read())
            {
                result.Add(generateMethod(reader, filterParameters));
            }

            DoPostCommandProcessing();

            return(result);
        }
Пример #6
0
 /// <summary>
 /// Executes the stored procedure with the given name, passes the provided parameters and used the generateMethod to return an instance of the passed generic type. You can pass optional filter parameters which are passed to the generateMethod
 /// </summary>
 /// <typeparam name="ClassName">The type of the class to return.</typeparam>
 /// <param name="storedProcedureName">Name of the stored procedure.</param>
 /// <param name="generateMethod">The method expecting a DataRow and return an instance of the passed generic type.</param>
 /// <param name="filterParameters">The filter parameters.</param>
 /// <param name="parameters">The parameters as objects in the shape of  paramname, paramvalue, paramname, paramvalue and so on.</param>
 /// <returns>An instance of the passed generic type</returns>
 public ClassName ExecuteClassQuery <ClassName>(string storedProcedureName, ObjectFromParameterizedDataReaderHandler <ClassName> generateMethod, object[] filterParameters, params object[] parameters)
 {
     return(ExecuteClassQuery(storedProcedureName, generateMethod, filterParameters, GetParametersFromObjectArray(parameters)));
 }