File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ static void Main(string[] args)
4646 var compiler = new SqlServerCompiler ( ) ;
4747 var sql = compiler . Compile ( query ) . Sql ;
4848 Console . WriteLine ( sql ) ;
49+
50+
51+ using ( var db = SqlLiteQueryFactory ( ) )
52+ {
53+ var accounts = db . Query ( "accounts" ) . Get ( ) ;
54+ Console . WriteLine ( accounts . Count ( ) ) ;
55+ }
4956 }
5057
5158 private static void log ( Compiler compiler , Query query )
@@ -79,6 +86,7 @@ private static QueryFactory SqlLiteQueryFactory()
7986 }
8087
8188 return db ;
89+
8290 }
8391
8492 private static QueryFactory SqlServerQueryFactory ( )
Original file line number Diff line number Diff line change 1010
1111namespace SqlKata . Execution
1212{
13- public class QueryFactory
13+ public class QueryFactory : IDisposable
1414 {
1515 public IDbConnection Connection { get ; set ; }
1616 public Compiler Compiler { get ; set ; }
1717 public Action < SqlResult > Logger = result => { } ;
18+ private bool disposedValue ;
19+
1820 public int QueryTimeout { get ; set ; } = 30 ;
1921
2022 public QueryFactory ( ) { }
@@ -823,5 +825,35 @@ internal SqlResult CompileAndLog(Query query)
823825 return compiled ;
824826 }
825827
828+ protected virtual void Dispose ( bool disposing )
829+ {
830+ if ( ! disposedValue )
831+ {
832+ if ( disposing )
833+ {
834+ Connection . Dispose ( ) ;
835+ }
836+
837+ // TODO: free unmanaged resources (unmanaged objects) and override finalizer
838+ // TODO: set large fields to null
839+ Connection = null ;
840+ Compiler = null ;
841+ disposedValue = true ;
842+ }
843+ }
844+
845+ // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
846+ // ~QueryFactory()
847+ // {
848+ // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
849+ // Dispose(disposing: false);
850+ // }
851+
852+ public void Dispose ( )
853+ {
854+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
855+ Dispose ( disposing : true ) ;
856+ GC . SuppressFinalize ( this ) ;
857+ }
826858 }
827859}
You can’t perform that action at this time.
0 commit comments