@@ -23,11 +23,12 @@ public static class Extensions
2323 /// <param name="name">The name of the parameter.</param>
2424 /// <param name="value">The value of the parameter.</param>
2525 /// <param name="type">The DbType of the parameter.</param>
26+ /// <param name="direction">The direction of the parameter.</param>
2627 /// <returns>The created IDbDataParameter.</returns>
27- public static IDbDataParameter AddParameter ( this SqlCommand target ,
28- string name , object value , SqlDbType type )
28+ public static SqlParameter AddParameter ( this SqlCommand target ,
29+ string name , object value , SqlDbType type , ParameterDirection direction = ParameterDirection . Input )
2930 {
30- var p = target . AddParameterType ( name , type ) ;
31+ var p = target . AddParameterType ( name , type , direction ) ;
3132 p . Value = value ;
3233 return p ;
3334 }
@@ -38,24 +39,27 @@ public static IDbDataParameter AddParameter(this SqlCommand target,
3839 /// <param name="target">The command to add a parameter to.</param>
3940 /// <param name="name">The name of the parameter.</param>
4041 /// <param name="type">The SqlDbType of the parameter.</param>
42+ /// <param name="direction">The direction of the parameter.</param>
4143 /// <returns>The created IDbDataParameter.</returns>
42- public static IDbDataParameter AddParameterType ( this SqlCommand target , string name , SqlDbType type )
44+ public static SqlParameter AddParameterType ( this SqlCommand target ,
45+ string name , SqlDbType type , ParameterDirection direction = ParameterDirection . Input )
4346 {
4447 var c = target . CreateParameter ( ) ;
4548 c . ParameterName = name ;
4649 c . SqlDbType = type ;
50+ c . Direction = direction ;
4751 target . Parameters . Add ( c ) ;
4852 return c ;
4953 }
50-
54+
5155 /// <summary>
5256 /// Shortcut for adding command a typed (non-input) parameter.
5357 /// </summary>
5458 /// <param name="target">The command to add a parameter to.</param>
5559 /// <param name="name">The name of the parameter.</param>
5660 /// <param name="type">The SqlDbType of the parameter.</param>
5761 /// <returns>The created IDbDataParameter.</returns>
58- public static IDbDataParameter AddParameterType ( this IDbCommand target , string name , SqlDbType type )
62+ public static SqlParameter AddParameterType ( this IDbCommand target , string name , SqlDbType type )
5963 {
6064 return AddParameterType ( ( SqlCommand ) target , name , type ) ;
6165 }
@@ -79,6 +83,24 @@ public static SqlCommand CreateCommand(this SqlConnection connection,
7983 return command ;
8084 }
8185
86+ /// <summary>
87+ /// Shortcut for creating an SqlCommand from any SqlConnection.
88+ /// </summary>
89+ /// <param name="connection">The connection to create a command from.</param>
90+ /// <param name="commandText">The command text or stored procedure name to use.</param>
91+ /// <param name="secondsTimeout">The number of seconds to wait before the command times out.</param>
92+ /// <returns>The created SqlCommand.</returns>
93+ public static SqlCommand CreateStoredProcedureCommand ( this SqlConnection connection ,
94+ string commandText , int secondsTimeout = CommandTimeout . DEFAULT_SECONDS )
95+ {
96+ var command = connection . CreateCommand ( ) ;
97+ command . CommandType = CommandType . StoredProcedure ;
98+ command . CommandText = commandText ;
99+ command . CommandTimeout = secondsTimeout ;
100+
101+ return command ;
102+ }
103+
82104 /// <summary>
83105 /// Asynchronously iterates all records using an IDataReader and returns the desired results as a list.
84106 /// </summary>
0 commit comments