示例#1
0
        public static T Connection <T>(this T command, string connectionName, DatabaseDriver driver = null)
            where T : Command
        {
            command._connection = ConnectionManager.GetConnection(connectionName);

            command.DatabaseDriver = driver != null ? driver : DatabaseDriverManager.Drivers[command._connection.ProviderName];

            return(command);
        }
示例#2
0
        /// <summary>
        /// Creates a database command from a connection
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="commandType"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="timeout"></param>
        /// <param name="driver"></param>
        /// <returns></returns>
        public static DbCommand CreateCommand(
            this DbConnection connection,
            CommandType commandType,
            string sql,
            IList <Parameter> parameters,
            int?timeout,
            DatabaseDriver driver)
        {
            var command = connection.CreateCommand();

            command.CommandType = commandType;

            if (timeout.HasValue)
            {
                command.CommandTimeout = timeout.Value;
            }

            if (string.IsNullOrEmpty(sql))
            {
                throw new ArgumentNullException("Must provide the SQL statement");
            }

            command.CommandText = sql;

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    command.AddParameter(
                        driver.ParameterPlaceHolder + parameter.Name,
                        parameter.Value,
                        parameter.Size,
                        parameter.Direction,
                        parameter.SqlType,
                        driver);
                }
            }

            return(command);
        }
示例#3
0
        public static T ConnectionString <T>(this T command, string connectionString, string providerName, DatabaseDriver driver = null)
            where T : Command
        {
            command._connection = new Connection
            {
                ConnectionString = connectionString,
                ProviderName     = providerName
            };

            command.DatabaseDriver = driver != null ? driver : DatabaseDriverManager.Drivers[command._connection.ProviderName];

            return(command);
        }