@@ -52,6 +52,14 @@ public class DataSession : DisposableBase, IDataSession
5252 /// </value>
5353 public IDataQueryLogger ? QueryLogger { get ; }
5454
55+ /// <summary>
56+ /// Gets the default command timeout in seconds.
57+ /// </summary>
58+ /// <value>
59+ /// The default command timeout in seconds.
60+ /// </value>
61+ public int ? CommandTimeout { get ; }
62+
5563 /// <summary>
5664 /// Gets the interceptors registered for this session.
5765 /// </summary>
@@ -69,6 +77,7 @@ public class DataSession : DisposableBase, IDataSession
6977 /// <param name="cache">The <see cref="IDataCache" /> used to cached results of queries.</param>
7078 /// <param name="queryGenerator">The query generator provider.</param>
7179 /// <param name="logger">The logger delegate for writing log messages.</param>
80+ /// <param name="commandTimeout">The default command timeout in seconds.</param>
7281 /// <param name="interceptors">The interceptors to apply during this session's lifetime.</param>
7382 /// <exception cref="ArgumentNullException"><paramref name="connection" /> is null</exception>
7483 /// <exception cref="ArgumentException">Invalid connection string on <paramref name="connection" /> instance.</exception>
@@ -78,7 +87,8 @@ public DataSession(
7887 IDataCache ? cache = null ,
7988 IQueryGenerator ? queryGenerator = null ,
8089 IDataQueryLogger ? logger = null ,
81- IEnumerable < IDataInterceptor > ? interceptors = null )
90+ IEnumerable < IDataInterceptor > ? interceptors = null ,
91+ int ? commandTimeout = null )
8292 {
8393 if ( connection == null )
8494 throw new ArgumentNullException ( nameof ( connection ) ) ;
@@ -90,6 +100,7 @@ public DataSession(
90100 Cache = cache ;
91101 QueryGenerator = queryGenerator ?? new SqlServerGenerator ( ) ;
92102 QueryLogger = logger ;
103+ CommandTimeout = commandTimeout ;
93104
94105 _interceptors = interceptors is null ? [ ] : [ .. interceptors ] ;
95106 _connectionInterceptors = [ .. _interceptors . OfType < IDataConnectionInterceptor > ( ) ] ;
@@ -106,6 +117,7 @@ public DataSession(
106117 /// <param name="cache">The <see cref="IDataCache" /> used to cached results of queries.</param>
107118 /// <param name="queryGenerator">The query generator provider.</param>
108119 /// <param name="logger">The logger delegate for writing log messages.</param>
120+ /// <param name="commandTimeout">The default command timeout in seconds.</param>
109121 /// <param name="interceptors">The interceptors to apply during this session's lifetime.</param>
110122 /// <exception cref="ArgumentNullException"><paramref name="transaction" /> is null</exception>
111123 /// <exception cref="ArgumentException">Invalid connection string on <paramref name="transaction" /> instance.</exception>
@@ -115,8 +127,9 @@ public DataSession(
115127 IDataCache ? cache = null ,
116128 IQueryGenerator ? queryGenerator = null ,
117129 IDataQueryLogger ? logger = null ,
118- IEnumerable < IDataInterceptor > ? interceptors = null )
119- : this ( GetTransactionConnection ( transaction ) , disposeConnection , cache , queryGenerator , logger , interceptors )
130+ IEnumerable < IDataInterceptor > ? interceptors = null ,
131+ int ? commandTimeout = null )
132+ : this ( GetTransactionConnection ( transaction ) , disposeConnection , cache , queryGenerator , logger , interceptors , commandTimeout )
120133 {
121134 Transaction = transaction ;
122135 }
@@ -135,6 +148,7 @@ public DataSession(IDataConfiguration dataConfiguration)
135148 Cache = dataConfiguration . DataCache ;
136149 QueryGenerator = dataConfiguration . QueryGenerator ;
137150 QueryLogger = dataConfiguration . QueryLogger ;
151+ CommandTimeout = dataConfiguration . CommandTimeout ;
138152
139153 _interceptors = dataConfiguration . Interceptors is null ? [ ] : [ .. dataConfiguration . Interceptors ] ;
140154 _connectionInterceptors = [ .. _interceptors . OfType < IDataConnectionInterceptor > ( ) ] ;
@@ -186,7 +200,7 @@ public async Task<DbTransaction> BeginTransactionAsync(IsolationLevel isolationL
186200 /// </returns>
187201 public IDataCommand Sql ( string sql )
188202 {
189- var dataCommand = new DataCommand ( this , Transaction , _commandInterceptors ) ;
203+ var dataCommand = new DataCommand ( this , Transaction , _commandInterceptors , commandTimeout : CommandTimeout ) ;
190204 return dataCommand . Sql ( sql ) ;
191205 }
192206
@@ -199,7 +213,7 @@ public IDataCommand Sql(string sql)
199213 /// </returns>
200214 public IDataCommand StoredProcedure ( string storedProcedureName )
201215 {
202- var dataCommand = new DataCommand ( this , Transaction , _commandInterceptors ) ;
216+ var dataCommand = new DataCommand ( this , Transaction , _commandInterceptors , commandTimeout : CommandTimeout ) ;
203217 return dataCommand . StoredProcedure ( storedProcedureName ) ;
204218 }
205219
@@ -389,6 +403,7 @@ public class DataSession<TDiscriminator> : DataSession, IDataSession<TDiscrimina
389403 /// <param name="cache">The <see cref="IDataCache" /> used to cached results of queries.</param>
390404 /// <param name="queryGenerator">The query generator provider.</param>
391405 /// <param name="logger">The logger delegate for writing log messages.</param>
406+ /// <param name="commandTimeout">The default command timeout in seconds.</param>
392407 /// <param name="interceptors">The interceptors to apply during this session's lifetime.</param>
393408 /// <exception cref="ArgumentNullException"><paramref name="connection" /> is null</exception>
394409 /// <exception cref="ArgumentException">Invalid connection string on <paramref name="connection" /> instance.</exception>
@@ -398,8 +413,9 @@ public DataSession(
398413 IDataCache ? cache = null ,
399414 IQueryGenerator ? queryGenerator = null ,
400415 IDataQueryLogger ? logger = null ,
401- IEnumerable < IDataInterceptor > ? interceptors = null )
402- : base ( connection , disposeConnection , cache , queryGenerator , logger , interceptors )
416+ IEnumerable < IDataInterceptor > ? interceptors = null ,
417+ int ? commandTimeout = null )
418+ : base ( connection , disposeConnection , cache , queryGenerator , logger , interceptors , commandTimeout )
403419 {
404420 }
405421
@@ -411,6 +427,7 @@ public DataSession(
411427 /// <param name="cache">The <see cref="IDataCache" /> used to cached results of queries.</param>
412428 /// <param name="queryGenerator">The query generator provider.</param>
413429 /// <param name="logger">The logger delegate for writing log messages.</param>
430+ /// <param name="commandTimeout">The default command timeout in seconds.</param>
414431 /// <param name="interceptors">The interceptors to apply during this session's lifetime.</param>
415432 /// <exception cref="ArgumentNullException"><paramref name="transaction" /> is null</exception>
416433 /// <exception cref="ArgumentException">Invalid connection string on <paramref name="transaction" /> instance.</exception>
@@ -420,8 +437,9 @@ public DataSession(
420437 IDataCache ? cache = null ,
421438 IQueryGenerator ? queryGenerator = null ,
422439 IDataQueryLogger ? logger = null ,
423- IEnumerable < IDataInterceptor > ? interceptors = null )
424- : base ( transaction , disposeConnection , cache , queryGenerator , logger , interceptors )
440+ IEnumerable < IDataInterceptor > ? interceptors = null ,
441+ int ? commandTimeout = null )
442+ : base ( transaction , disposeConnection , cache , queryGenerator , logger , interceptors , commandTimeout )
425443 {
426444 }
427445
0 commit comments