44using Microsoft . EntityFrameworkCore . Storage ;
55using Microsoft . Extensions . Logging ;
66
7- using PhenX . EntityFrameworkCore . BulkInsert . Abstractions ;
87using PhenX . EntityFrameworkCore . BulkInsert . Dialect ;
98using PhenX . EntityFrameworkCore . BulkInsert . Extensions ;
109using PhenX . EntityFrameworkCore . BulkInsert . Metadata ;
1110using PhenX . EntityFrameworkCore . BulkInsert . Options ;
1211
1312namespace PhenX . EntityFrameworkCore . BulkInsert ;
1413
15- internal abstract class BulkInsertProviderBase < TDialect , TOptions > ( ILogger < BulkInsertProviderBase < TDialect , TOptions > > logger ) : IBulkInsertProvider
14+ internal abstract class BulkInsertProviderBase < TDialect , TOptions > ( ILogger ? logger ) : BulkInsertProviderUntyped < TDialect , TOptions >
1615 where TDialect : SqlDialectBuilder , new ( )
1716 where TOptions : BulkInsertOptions , new ( )
1817{
19- protected readonly TDialect SqlDialect = new ( ) ;
20-
2118 protected virtual string BulkInsertId => "_bulk_insert_id" ;
2219
2320 protected abstract string AddTableCopyBulkInsertId { get ; }
2421
2522 protected virtual string GetTempTableName ( string tableName ) => $ "_temp_bulk_insert_{ tableName } ";
2623
27- SqlDialectBuilder IBulkInsertProvider . SqlDialect => SqlDialect ;
28-
29- public BulkInsertOptions InternalCreateDefaultOptions ( ) => CreateDefaultOptions ( ) ;
30-
31- /// <summary>
32- /// Create the default options for the provider, can be a subclass of <see cref="BulkInsertOptions"/>.
33- /// </summary>
34- protected abstract TOptions CreateDefaultOptions ( ) ;
35-
36- public virtual async IAsyncEnumerable < T > BulkInsertReturnEntities < T > (
24+ protected override async IAsyncEnumerable < T > BulkInsertReturnEntities < T > (
3725 bool sync ,
3826 DbContext context ,
3927 TableMetadata tableInfo ,
4028 IEnumerable < T > entities ,
41- BulkInsertOptions options ,
42- OnConflictOptions ? onConflict ,
29+ TOptions options ,
30+ OnConflictOptions < T > ? onConflict ,
4331 [ EnumeratorCancellation ] CancellationToken ctk ) where T : class
4432 {
45- if ( options is not TOptions providerOptions )
46- {
47- throw new InvalidOperationException ( $ "Invalid options type: { options . GetType ( ) . Name } . Expected: { typeof ( TOptions ) . Name } ") ;
48- }
49-
5033 using var activity = Telemetry . ActivitySource . StartActivity ( "BulkInsertReturnEntities" ) ;
5134 activity ? . AddTag ( "tableName" , tableInfo . TableName ) ;
5235 activity ? . AddTag ( "synchronous" , sync ) ;
@@ -59,10 +42,10 @@ public virtual async IAsyncEnumerable<T> BulkInsertReturnEntities<T>(
5942 Log . UsingTempTableToReturnData ( logger ) ;
6043 }
6144
62- var tableName = await PerformBulkInsertAsync ( sync , context , tableInfo , entities , providerOptions , tempTableRequired : true , ctk : ctk ) ;
45+ var tableName = await PerformBulkInsertAsync ( sync , context , tableInfo , entities , options , tempTableRequired : true , ctk : ctk ) ;
6346
6447 var result =
65- await CopyFromTempTableAsync < T , T > ( sync , context , tableInfo , tableName , true , providerOptions , onConflict , ctk : ctk )
48+ await CopyFromTempTableAsync < T , T > ( sync , context , tableInfo , tableName , true , options , onConflict , ctk : ctk )
6649 ?? throw new InvalidOperationException ( "Copy returns null enumerable." ) ;
6750
6851 await foreach ( var item in result . WithCancellation ( ctk ) )
@@ -79,20 +62,15 @@ await CopyFromTempTableAsync<T, T>(sync, context, tableInfo, tableName, true, pr
7962 }
8063 }
8164
82- public virtual async Task BulkInsert < T > (
65+ protected override async Task BulkInsert < T > (
8366 bool sync ,
8467 DbContext context ,
8568 TableMetadata tableInfo ,
8669 IEnumerable < T > entities ,
87- BulkInsertOptions options ,
88- OnConflictOptions ? onConflict ,
70+ TOptions options ,
71+ OnConflictOptions < T > ? onConflict ,
8972 CancellationToken ctk ) where T : class
9073 {
91- if ( options is not TOptions providerOptions )
92- {
93- throw new InvalidOperationException ( $ "Invalid options type: { options . GetType ( ) . Name } . Expected: { typeof ( TOptions ) . Name } ") ;
94- }
95-
9674 using var activity = Telemetry . ActivitySource . StartActivity ( "BulkInsert" ) ;
9775 activity ? . AddTag ( "tableName" , tableInfo . TableName ) ;
9876 activity ? . AddTag ( "synchronous" , sync ) ;
@@ -107,9 +85,9 @@ public virtual async Task BulkInsert<T>(
10785 Log . UsingTempTableToResolveConflicts ( logger ) ;
10886 }
10987
110- var tableName = await PerformBulkInsertAsync ( sync , context , tableInfo , entities , providerOptions , tempTableRequired : true , ctk : ctk ) ;
88+ var tableName = await PerformBulkInsertAsync ( sync , context , tableInfo , entities , options , tempTableRequired : true , ctk : ctk ) ;
11189
112- await CopyFromTempTableAsync < T , T > ( sync , context , tableInfo , tableName , false , providerOptions , onConflict , ctk ) ;
90+ await CopyFromTempTableAsync < T , T > ( sync , context , tableInfo , tableName , false , options , onConflict , ctk ) ;
11391 }
11492 else
11593 {
@@ -118,7 +96,7 @@ public virtual async Task BulkInsert<T>(
11896 Log . UsingDirectInsert ( logger ) ;
11997 }
12098
121- await PerformBulkInsertAsync ( sync , context , tableInfo , entities , providerOptions , tempTableRequired : false , ctk : ctk ) ;
99+ await PerformBulkInsertAsync ( sync , context , tableInfo , entities , options , tempTableRequired : false , ctk : ctk ) ;
122100 }
123101
124102 // Commit the transaction if we own them.
@@ -207,7 +185,7 @@ protected virtual async Task AddBulkInsertIdColumn<T>(
207185 string tempTableName ,
208186 bool returnData ,
209187 TOptions options ,
210- OnConflictOptions ? onConflict ,
188+ OnConflictOptions < T > ? onConflict ,
211189 CancellationToken ctk ) where T : class where TResult : class
212190 {
213191 var query =
0 commit comments