@@ -39,7 +39,7 @@ public PostgreSQLCopyHelper(string schemaName, string tableName)
3939 }
4040
4141 public ulong SaveAll ( NpgsqlConnection connection , IEnumerable < TEntity > entities ) =>
42- DoSaveAllAsync ( connection , entities ) . GetAwaiter ( ) . GetResult ( ) ;
42+ DoSaveAllAsync ( connection , entities , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
4343
4444 public ValueTask < ulong > SaveAllAsync ( NpgsqlConnection connection , IEnumerable < TEntity > entities , CancellationToken cancellationToken = default )
4545 {
@@ -50,7 +50,7 @@ public ValueTask<ulong> SaveAllAsync(NpgsqlConnection connection, IEnumerable<TE
5050
5151 using ( NoSynchronizationContextScope . Enter ( ) )
5252 {
53- return DoSaveAllAsync ( connection , entities ) ;
53+ return DoSaveAllAsync ( connection , entities , cancellationToken ) ;
5454 }
5555 }
5656
@@ -67,20 +67,20 @@ public ValueTask<ulong> SaveAllAsync(NpgsqlConnection connection, IAsyncEnumerab
6767 }
6868 }
6969
70- private async ValueTask < ulong > DoSaveAllAsync ( NpgsqlConnection connection , IEnumerable < TEntity > entities )
70+ private async ValueTask < ulong > DoSaveAllAsync ( NpgsqlConnection connection , IEnumerable < TEntity > entities , CancellationToken cancellationToken )
7171 {
7272 await using var binaryCopyWriter = connection . BeginBinaryImport ( GetCopyCommand ( ) ) ;
73- await WriteToStream ( binaryCopyWriter , entities ) ;
73+ await WriteToStreamAsync ( binaryCopyWriter , entities , cancellationToken ) ;
7474
75- return await binaryCopyWriter . CompleteAsync ( ) ;
75+ return await binaryCopyWriter . CompleteAsync ( cancellationToken ) ;
7676 }
7777
7878 private async ValueTask < ulong > DoSaveAllAsync ( NpgsqlConnection connection , IAsyncEnumerable < TEntity > entities , CancellationToken cancellationToken )
7979 {
8080 await using var binaryCopyWriter = connection . BeginBinaryImport ( GetCopyCommand ( ) ) ;
8181 await WriteToStreamAsync ( binaryCopyWriter , entities , cancellationToken ) ;
8282
83- return await binaryCopyWriter . CompleteAsync ( ) ;
83+ return await binaryCopyWriter . CompleteAsync ( cancellationToken ) ;
8484 }
8585
8686 public PostgreSQLCopyHelper < TEntity > UsePostgresQuoting ( bool enabled = true )
@@ -113,29 +113,29 @@ public PostgreSQLCopyHelper<TEntity> MapNullable<TProperty>(string columnName, F
113113 } ) ;
114114 }
115115
116- private async Task WriteToStream ( NpgsqlBinaryImporter writer , IEnumerable < TEntity > entities )
116+ private async Task WriteToStreamAsync ( NpgsqlBinaryImporter writer , IEnumerable < TEntity > entities , CancellationToken cancellationToken )
117117 {
118118 foreach ( var entity in entities )
119119 {
120- await writer . StartRowAsync ( ) ;
121-
122- foreach ( var columnDefinition in _columns )
123- {
124- await columnDefinition . Write ( writer , entity ) ;
125- }
120+ await WriteToStreamAsync ( writer , entity , cancellationToken ) ;
126121 }
127122 }
128123
129124 private async Task WriteToStreamAsync ( NpgsqlBinaryImporter writer , IAsyncEnumerable < TEntity > entities , CancellationToken cancellationToken )
130125 {
131126 await foreach ( var entity in entities . WithCancellation ( cancellationToken ) )
132127 {
133- await writer . StartRowAsync ( cancellationToken : cancellationToken ) ;
128+ await WriteToStreamAsync ( writer , entity , cancellationToken ) ;
129+ }
130+ }
134131
135- foreach ( var columnDefinition in _columns )
136- {
137- await columnDefinition . Write ( writer , entity ) ;
138- }
132+ private async Task WriteToStreamAsync ( NpgsqlBinaryImporter writer , TEntity entity , CancellationToken cancellationToken )
133+ {
134+ await writer . StartRowAsync ( cancellationToken ) ;
135+
136+ foreach ( var columnDefinition in _columns )
137+ {
138+ await columnDefinition . Write ( writer , entity ) ;
139139 }
140140 }
141141
0 commit comments