@@ -396,17 +396,28 @@ private bool IsTableInlined(ClassExtensionModel model)
396396
397397 private bool RequiresToTableStatementForConvention ( string className )
398398 {
399- switch ( ExecutionContext . Settings . GetDatabaseSettings ( ) . TableNamingConvention ( ) . AsEnum ( ) )
399+ var tableNamingConvention = ExecutionContext . Settings . GetDatabaseSettings ( ) . TableNamingConvention ( ) . AsEnum ( ) ;
400+ var dbSetNamingConvention = ExecutionContext . Settings . GetDatabaseSettings ( ) . DBSetNamingConvention ( ) . AsEnum ( ) ;
401+
402+ // Compute the expected table name based on the table naming convention
403+ string expectedTableName = tableNamingConvention switch
400404 {
401- case DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . Singularized :
402- return true ;
403- case DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . None :
404- //Because DBSets are plural table names default to table, we need to add ToTables in the name is not pluralized
405- return className != className . Pluralize ( ) ;
406- case DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . Pluralized :
407- default :
408- return false ;
409- }
405+ DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . Pluralized => className . Pluralize ( ) ,
406+ DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . Singularized => className . Singularize ( ) ,
407+ DatabaseSettingsExtensions . TableNamingConventionOptionsEnum . None => className ,
408+ _ => className
409+ } ;
410+
411+ // Compute the DbSet name based on the DBSet naming convention
412+ string dbSetName = dbSetNamingConvention switch
413+ {
414+ DatabaseSettingsExtensions . DBSetNamingConventionOptionsEnum . Pluralized => className . Pluralize ( ) ,
415+ DatabaseSettingsExtensions . DBSetNamingConventionOptionsEnum . SameAsEntity => className ,
416+ _ => className
417+ } ;
418+
419+ // If the DbSet name does not match the expected table name, ToTable is required
420+ return dbSetName != expectedTableName ;
410421 }
411422
412423 private string GetTableNameByConvention ( string className )
0 commit comments