Skip to content

Commit 855d3c1

Browse files
committed
Merge pull request DapperLib#284 from Irrational86/master
SqlMapper global/default CommandTimeout
2 parents cb91e67 + c645cb5 commit 855d3c1

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Dapper NET40/SqlMapper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
183183
cmd.Transaction = transaction;
184184
cmd.CommandText = commandText;
185185
if (commandTimeout.HasValue)
186+
{
186187
cmd.CommandTimeout = commandTimeout.Value;
188+
}
189+
else if (SqlMapper.Settings.CommandTimeout.HasValue)
190+
{
191+
cmd.CommandTimeout = SqlMapper.Settings.CommandTimeout.Value;
192+
}
187193
if (commandType.HasValue)
188194
cmd.CommandType = commandType.Value;
189195
if (paramReader != null)
@@ -252,6 +258,30 @@ static MethodInfo GetBasicPropertySetter(Type declaringType, string name, Type e
252258
/// </summary>
253259
static partial class SqlMapper
254260
{
261+
/// <summary>
262+
/// Permits specifying certain SqlMapper values globally.
263+
/// </summary>
264+
public static class Settings
265+
{
266+
static Settings()
267+
{
268+
SetDefaults();
269+
}
270+
271+
/// <summary>
272+
/// Resets all Settings to their default values
273+
/// </summary>
274+
public static void SetDefaults()
275+
{
276+
CommandTimeout = null;
277+
}
278+
279+
/// <summary>
280+
/// Specifies the default Command Timeout for all Queries
281+
/// </summary>
282+
public static int? CommandTimeout { get; set; }
283+
}
284+
255285
/// <summary>
256286
/// Implement this interface to pass an arbitrary db specific set of parameters to Dapper
257287
/// </summary>

0 commit comments

Comments
 (0)