コード例 #1
0
        /// <summary>
        /// Executes the given command text against the connection associated with <see cref="DbScope"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scope"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static int Execute <T>(this DbScope scope, string commandText,
                                      System.Data.CommandType commandType = System.Data.CommandType.Text,
                                      int?commandTimeout = null,
                                      object parameters  = null
                                      )
        {
            var cmd = new Dapper.CommandDefinition(commandText,
                                                   commandType: commandType,
                                                   parameters: parameters,
                                                   transaction: scope.Transaction,
                                                   commandTimeout: commandTimeout
                                                   );

            return(Dapper.SqlMapper.Execute(scope.Connection, cmd));
        }
コード例 #2
0
        /// <summary>
        /// Executes the given query text against the connection associated with <see cref="DbScope"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scope"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <T> > QueryAsync <T>(this DbScope scope, string commandText,
                                                                   System.Data.CommandType commandType = System.Data.CommandType.Text,
                                                                   int?commandTimeout = null,
                                                                   object parameters  = null
                                                                   )
        {
            var cmd = new Dapper.CommandDefinition(commandText,
                                                   commandType: commandType,
                                                   parameters: parameters,
                                                   transaction: scope.Transaction,
                                                   commandTimeout: commandTimeout
                                                   );

            return(await Dapper.SqlMapper.QueryAsync <T>(scope.Connection, cmd));
        }