11namespace DotNetToolkit . Repository . AdoNet . Internal . Schema
22{
3- using Configuration . Conventions ;
4- using Configuration . Logging ;
53 using Extensions ;
64 using Extensions . Internal ;
75 using Properties ;
@@ -24,7 +22,6 @@ internal class SchemaTableConfigurationHelper
2422 {
2523 #region Fields
2624
27- private readonly IRepositoryConventions _conventions ;
2825 private readonly DbHelper _dbHelper ;
2926 private readonly Dictionary < Type , bool > _tableCreationMapping = new Dictionary < Type , bool > ( ) ;
3027 private readonly Dictionary < Type , Tuple < string , Type > > _foreignTableCreationMapping = new Dictionary < Type , Tuple < string , Type > > ( ) ;
@@ -37,11 +34,9 @@ internal class SchemaTableConfigurationHelper
3734 /// <summary>
3835 /// Initializes a new instance of the <see cref="SchemaTableConfigurationHelper"/> class.
3936 /// </summary>
40- /// <param name="conventions">The configurable conventions.</param>
4137 /// <param name="dbHelper">The database helper.</param>
42- public SchemaTableConfigurationHelper ( IRepositoryConventions conventions , DbHelper dbHelper )
38+ public SchemaTableConfigurationHelper ( DbHelper dbHelper )
4339 {
44- _conventions = Guard . NotNull ( conventions , nameof ( conventions ) ) ;
4540 _dbHelper = Guard . NotNull ( dbHelper , nameof ( dbHelper ) ) ;
4641 }
4742
@@ -182,7 +177,7 @@ private bool ExecuteTableExists(Type entityType)
182177 if ( entityType == null )
183178 throw new ArgumentNullException ( nameof ( entityType ) ) ;
184179
185- var tableName = _conventions . GetTableName ( entityType ) ;
180+ var tableName = _dbHelper . Conventions . GetTableName ( entityType ) ;
186181 var sql = @"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @tableName" ;
187182 var parameters = new Dictionary < string , object > { { "@tableName" , tableName } } ;
188183
@@ -206,7 +201,7 @@ private void ExecuteTableValidate(Type entityType)
206201 if ( entityType == null )
207202 throw new ArgumentNullException ( nameof ( entityType ) ) ;
208203
209- var tableName = _conventions . GetTableName ( entityType ) ;
204+ var tableName = _dbHelper . Conventions . GetTableName ( entityType ) ;
210205 var schemaTableColumns = GetSchemaTableColumns ( tableName ) ;
211206
212207 ValidateTable ( entityType , schemaTableColumns , tableName ) ;
@@ -217,7 +212,7 @@ private async Task ExecuteTableValidateAsync(Type entityType, CancellationToken
217212 if ( entityType == null )
218213 throw new ArgumentNullException ( nameof ( entityType ) ) ;
219214
220- var tableName = _conventions . GetTableName ( entityType ) ;
215+ var tableName = _dbHelper . Conventions . GetTableName ( entityType ) ;
221216 var schemaTableColumns = await GetSchemaTableColumnsAsync ( tableName , cancellationToken ) ;
222217
223218 ValidateTable ( entityType , schemaTableColumns , tableName ) ;
@@ -230,8 +225,8 @@ private void ValidateTable(Type entityType, IEnumerable<SchemaTableColumn> schem
230225 var propertiesMapping = entityType
231226 . GetRuntimeProperties ( )
232227 . Where ( x => x . IsPrimitive ( ) )
233- . OrderBy ( _conventions . GetColumnOrderOrDefault )
234- . ToDictionary ( _conventions . GetColumnName , x => x ) ;
228+ . OrderBy ( _dbHelper . Conventions . GetColumnOrderOrDefault )
229+ . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => x ) ;
235230
236231 var columns = propertiesMapping . Keys . ToArray ( ) ;
237232
@@ -247,14 +242,14 @@ private void ValidateTable(Type entityType, IEnumerable<SchemaTableColumn> schem
247242
248243 // Gets all the constraints
249244 var schemaTableColumnConstraintsMapping = GetSchemaTableColumnConstraintsMapping ( tableName , columns ) ;
250- var primaryKeyPropertiesMapping = _conventions . GetPrimaryKeyPropertyInfos ( entityType ) . ToDictionary ( _conventions . GetColumnName , x => x ) ;
245+ var primaryKeyPropertiesMapping = _dbHelper . Conventions . GetPrimaryKeyPropertyInfos ( entityType ) . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => x ) ;
251246
252247 // Gets all the foreign keys
253248 var foreignKeyPropertyInfosMapping = entityType
254249 . GetRuntimeProperties ( )
255250 . Where ( x => x . IsComplex ( ) )
256- . Select ( pi => _conventions . GetForeignKeyPropertyInfos ( entityType , pi . PropertyType )
257- . ToDictionary ( _conventions . GetColumnName , x => pi ) )
251+ . Select ( pi => _dbHelper . Conventions . GetForeignKeyPropertyInfos ( entityType , pi . PropertyType )
252+ . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => pi ) )
258253 . SelectMany ( x => x )
259254 . ToDictionary ( x => x . Key , x => x . Value ) ;
260255
@@ -284,7 +279,7 @@ private void ValidateTable(Type entityType, IEnumerable<SchemaTableColumn> schem
284279 {
285280 var foreignPropertyInfo = foreignKeyPropertyInfosMapping [ columnName ] ;
286281
287- if ( _conventions . HasCompositePrimaryKey ( foreignPropertyInfo . PropertyType ) )
282+ if ( _dbHelper . Conventions . HasCompositePrimaryKey ( foreignPropertyInfo . PropertyType ) )
288283 {
289284 order = schemaTableColumn . OrdinalPosition - ( schemaTableColumn . OrdinalPosition - columnAttribute . Order ) ;
290285 }
@@ -474,10 +469,10 @@ private Dictionary<Type, string> GetPreparedCreateTableQueriesMapping(Type entit
474469
475470 private string PrepareCreateTableQuery ( Type entityType )
476471 {
477- var tableName = _conventions . GetTableName ( entityType ) ;
472+ var tableName = _dbHelper . Conventions . GetTableName ( entityType ) ;
478473
479474 // Check if has composite primary keys (more than one key), and if so, it needs to defined an ordering
480- var primaryKeyPropertyInfos = _conventions . GetPrimaryKeyPropertyInfos ( entityType ) ;
475+ var primaryKeyPropertyInfos = _dbHelper . Conventions . GetPrimaryKeyPropertyInfos ( entityType ) ;
481476 if ( primaryKeyPropertyInfos . Count ( ) > 1 )
482477 {
483478 var keysHaveNoOrdering = primaryKeyPropertyInfos . Any ( x => x . GetCustomAttribute < ColumnAttribute > ( ) == null ) ;
@@ -495,10 +490,10 @@ private string PrepareCreateTableQuery(Type entityType)
495490 // Check if has composite foreign keys (more than one key for a given navigation property), and if so, it needs to defined an ordering
496491 var propertiesMapping = properties
497492 . Where ( x => x . IsPrimitive ( ) )
498- . OrderBy ( _conventions . GetColumnOrderOrDefault )
499- . ToDictionary ( _conventions . GetColumnName , x => x ) ;
493+ . OrderBy ( _dbHelper . Conventions . GetColumnOrderOrDefault )
494+ . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => x ) ;
500495
501- var primaryKeyPropertyInfosMapping = _conventions . GetPrimaryKeyPropertyInfos ( entityType ) . ToDictionary ( _conventions . GetColumnName , x => x ) ;
496+ var primaryKeyPropertyInfosMapping = _dbHelper . Conventions . GetPrimaryKeyPropertyInfos ( entityType ) . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => x ) ;
502497 var primaryKeyConstraints = new List < string > ( ) ;
503498 var foreignKeyConstraints = new Dictionary < string , List < Tuple < string , string > > > ( ) ;
504499 var foreignKeyOrder = 0 ;
@@ -549,10 +544,10 @@ private string PrepareCreateTableQuery(Type entityType)
549544
550545 if ( hasPrincipal )
551546 {
552- var foreignNavigationTableName = _conventions . GetTableName ( foreignNavigationType ) ;
553- var foreignPrimaryKeyColumnNames = _conventions
547+ var foreignNavigationTableName = _dbHelper . Conventions . GetTableName ( foreignNavigationType ) ;
548+ var foreignPrimaryKeyColumnNames = _dbHelper . Conventions
554549 . GetPrimaryKeyPropertyInfos ( foreignNavigationType )
555- . Select ( _conventions . GetColumnName ) ;
550+ . Select ( _dbHelper . Conventions . GetColumnName ) ;
556551 var foreignPrimaryKeyColumnName = foreignPrimaryKeyColumnNames . ElementAt ( foreignKeyOrder ++ ) ;
557552
558553 if ( ! foreignKeyConstraints . ContainsKey ( foreignNavigationTableName ) )
@@ -590,7 +585,7 @@ private string PrepareCreateTableQuery(Type entityType)
590585 }
591586
592587 // Constraints
593- if ( _conventions . IsColumnIdentity ( item . Value ) )
588+ if ( _dbHelper . Conventions . IsColumnIdentity ( item . Value ) )
594589 {
595590 sb . Append ( "IDENTITY " ) ;
596591 }
@@ -624,7 +619,7 @@ private string PrepareCreateTableQuery(Type entityType)
624619 if ( ! foreignKeyConstraints . Any ( ) )
625620 {
626621 var primaryKeyPropertyInfo = primaryKeyPropertyInfosMapping . First ( ) . Value ;
627- var primaryKeyName = _conventions . GetColumnName ( primaryKeyPropertyInfo ) ;
622+ var primaryKeyName = _dbHelper . Conventions . GetColumnName ( primaryKeyPropertyInfo ) ;
628623
629624 var keyMappingFromForeign = GetForeignKeyPropertyInfosMapping ( entityType , true ) ;
630625
@@ -673,8 +668,8 @@ private Dictionary<string, PropertyInfo> GetForeignKeyPropertyInfosMapping(Type
673668 foreach ( var pi in foreignNavigationPropertyInfos )
674669 {
675670 var foreignKeyPropertyInfos = getFromForeign
676- ? _conventions . GetForeignKeyPropertyInfos ( pi . PropertyType , entityType )
677- : _conventions . GetForeignKeyPropertyInfos ( entityType , pi . PropertyType ) ;
671+ ? _dbHelper . Conventions . GetForeignKeyPropertyInfos ( pi . PropertyType , entityType )
672+ : _dbHelper . Conventions . GetForeignKeyPropertyInfos ( entityType , pi . PropertyType ) ;
678673
679674 if ( foreignKeyPropertyInfos . Any ( ) )
680675 {
@@ -686,7 +681,7 @@ private Dictionary<string, PropertyInfo> GetForeignKeyPropertyInfosMapping(Type
686681 Resources . UnableToDetermineCompositePrimaryKeyOrdering , "foreign" , entityType . FullName ) ) ;
687682 }
688683
689- var dict = foreignKeyPropertyInfos . ToDictionary ( _conventions . GetColumnName , x => pi ) ;
684+ var dict = foreignKeyPropertyInfos . ToDictionary ( _dbHelper . Conventions . GetColumnName , x => pi ) ;
690685
691686 foreach ( var item in dict )
692687 {
@@ -703,7 +698,7 @@ private async Task<bool> ExecuteTableExistsAsync(Type entityType, CancellationTo
703698 if ( entityType == null )
704699 throw new ArgumentNullException ( nameof ( entityType ) ) ;
705700
706- var tableName = _conventions . GetTableName ( entityType ) ;
701+ var tableName = _dbHelper . Conventions . GetTableName ( entityType ) ;
707702 var sql = @"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @tableName" ;
708703 var parameters = new Dictionary < string , object > { { "@tableName" , tableName } } ;
709704
0 commit comments