@@ -158,12 +158,15 @@ private static (MigrationResult migrationResult, List<string>) BuildDataSourceSh
158158 shardings . ForEach ( aShardingTable =>
159159 {
160160 string newCmd = sourceCmd ;
161- GetReplaceGroups ( operation , absTableName , aShardingTable ) . ForEach ( aReplace =>
161+ var replaceGroups = GetReplaceGroups ( operation , absTableName , aShardingTable ) ;
162+ foreach ( var migrationReplaceItem in replaceGroups )
162163 {
164+ var delimitSourceNameIdentifier = sqlGenerationHelper . DelimitIdentifier ( migrationReplaceItem . SourceName ) ;
165+ var delimitTargetNameIdentifier = sqlGenerationHelper . DelimitIdentifier ( migrationReplaceItem . TargetName ) ;
163166 newCmd = newCmd . Replace (
164- sqlGenerationHelper . DelimitIdentifier ( aReplace . sourceName ) ,
165- sqlGenerationHelper . DelimitIdentifier ( aReplace . targetName ) ) ;
166- } ) ;
167+ delimitSourceNameIdentifier ,
168+ delimitTargetNameIdentifier ) ;
169+ }
167170 if ( newCmd . Contains (
168171 "EXEC sp_addextendedproperty 'MS_Description', @description, 'SCHEMA', @defaultSchema, 'TABLE'" ) )
169172 {
@@ -185,13 +188,13 @@ string BuildPattern(string absTableName)
185188 }
186189 }
187190
188- private static List < ( string sourceName , string targetName ) > GetReplaceGroups (
191+ private static ISet < MigrationReplaceItem > GetReplaceGroups (
189192 MigrationOperation operation , string sourceTableName , string targetTableName )
190193 {
191- List < ( string sourceName , string targetName ) > resList =
192- new List < ( string sourceName , string targetName ) >
194+ ISet < MigrationReplaceItem > resList =
195+ new HashSet < MigrationReplaceItem > ( )
193196 {
194- ( sourceTableName , targetTableName )
197+ new MigrationReplaceItem ( sourceTableName , targetTableName )
195198 } ;
196199
197200 string name = operation . GetPropertyValue ( "Name" ) as string ;
@@ -209,7 +212,7 @@ string BuildPattern(string absTableName)
209212 if ( Regex . IsMatch ( name , aPattern ) )
210213 {
211214 var newName = new Regex ( aPattern ) . Replace ( name , "${1}" + targetTableName + "$3" ) ;
212- resList . Add ( ( name , newName ) ) ;
215+ resList . Add ( new MigrationReplaceItem ( name , newName ) ) ;
213216 break ;
214217 }
215218 }
@@ -235,14 +238,22 @@ string BuildPattern(string absTableName)
235238 var propertyValue = aProperty . GetValue ( operation ) ;
236239 if ( propertyValue is MigrationOperation propertyOperation )
237240 {
238- resList . AddRange ( GetReplaceGroups ( propertyOperation , sourceTableName , targetTableName ) ) ;
241+ var migrationReplaceItems = GetReplaceGroups ( propertyOperation , sourceTableName , targetTableName ) ;
242+ foreach ( var migrationReplaceItem in migrationReplaceItems )
243+ {
244+ resList . Add ( migrationReplaceItem ) ;
245+ }
239246 }
240247 else if ( listPropertyWhere ( aProperty ) )
241248 {
242249 foreach ( var aValue in ( IEnumerable ) propertyValue )
243250 {
244- resList . AddRange ( GetReplaceGroups ( ( MigrationOperation ) aValue , sourceTableName ,
245- targetTableName ) ) ;
251+ var migrationReplaceItems = GetReplaceGroups ( ( MigrationOperation ) aValue , sourceTableName ,
252+ targetTableName ) ;
253+ foreach ( var migrationReplaceItem in migrationReplaceItems )
254+ {
255+ resList . Add ( migrationReplaceItem ) ;
256+ }
246257 }
247258 }
248259 } ) ;
0 commit comments