@@ -35,6 +35,9 @@ public class SqlServerMigrationsSqlGenerator : MigrationsSqlGenerator
35
35
36
36
private readonly ICommandBatchPreparer _commandBatchPreparer ;
37
37
38
+ private static readonly bool QuirkEnabled29619
39
+ = AppContext . TryGetSwitch ( "Microsoft.EntityFrameworkCore.Issue29619" , out var enabled ) && enabled ;
40
+
38
41
/// <summary>
39
42
/// Creates a new <see cref="SqlServerMigrationsSqlGenerator" /> instance.
40
43
/// </summary>
@@ -369,17 +372,45 @@ protected override void Generate(
369
372
defaultValueSql = typeMapping . GenerateSqlLiteral ( operation . DefaultValue ) ;
370
373
}
371
374
372
- builder
373
- . Append ( "UPDATE " )
374
- . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Table , operation . Schema ) )
375
- . Append ( " SET " )
376
- . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Name ) )
377
- . Append ( " = " )
378
- . Append ( defaultValueSql )
379
- . Append ( " WHERE " )
380
- . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Name ) )
381
- . Append ( " IS NULL" )
382
- . AppendLine ( Dependencies . SqlGenerationHelper . StatementTerminator ) ;
375
+ if ( QuirkEnabled29619 )
376
+ {
377
+ builder
378
+ . Append ( "UPDATE " )
379
+ . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Table , operation . Schema ) )
380
+ . Append ( " SET " )
381
+ . Append ( defaultValueSql )
382
+ . Append ( " WHERE " )
383
+ . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Name ) )
384
+ . Append ( " IS NULL" )
385
+ . AppendLine ( Dependencies . SqlGenerationHelper . StatementTerminator ) ;
386
+ }
387
+ else
388
+ {
389
+ var updateBuilder = new StringBuilder ( )
390
+ . Append ( "UPDATE " )
391
+ . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Table , operation . Schema ) )
392
+ . Append ( " SET " )
393
+ . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Name ) )
394
+ . Append ( " = " )
395
+ . Append ( defaultValueSql )
396
+ . Append ( " WHERE " )
397
+ . Append ( Dependencies . SqlGenerationHelper . DelimitIdentifier ( operation . Name ) )
398
+ . Append ( " IS NULL" ) ;
399
+
400
+ if ( Options . HasFlag ( MigrationsSqlGenerationOptions . Idempotent ) )
401
+ {
402
+ builder
403
+ . Append ( "EXEC(N'" )
404
+ . Append ( updateBuilder . ToString ( ) . TrimEnd ( '\n ' , '\r ' , ';' ) . Replace ( "'" , "''" ) )
405
+ . Append ( "')" ) ;
406
+ }
407
+ else
408
+ {
409
+ builder . Append ( updateBuilder . ToString ( ) ) ;
410
+ }
411
+
412
+ builder . AppendLine ( Dependencies . SqlGenerationHelper . StatementTerminator ) ;
413
+ }
383
414
}
384
415
385
416
if ( alterStatementNeeded )
0 commit comments