You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've upgraded to EF Core 8.0.0 (from 7.0.8) and have started experiencing an issue with MigrationBuilder.Sql where all empty lines are dropped from the SQL executed by the resulting migration. This seems to be a result of the change in SqlServerMigrationsSqlGenerator.Generate(SqlOperation operation...) that was done to fix a regex timeout.
In the current code, it seems that new string.IsNullOrWhiteSpace(line) check is causing this issue. Here's the related snippet from SqlServerMigrationsSqlGenerator:
While some empty lines could be considered inconsequential, some are not, and currently all of them seem to be removed. For example, a migration like this:
publicpartialclassTestMigrationWithLineBreaks:Migration{protectedoverridevoidUp(MigrationBuildermigrationBuilder){migrationBuilder.Sql("INSERT INTO SomeTable SELECT 'Some\n\nValue'");}protectedoverridevoidDown(MigrationBuildermigrationBuilder){}}
Results in the below SQL execution (note the missing empty line):
Another of our current use cases involves using MigrationBuilder.Sql to manage changes to stored procedures and other db objects, and the dropped empty lines reduce readability of the definitions for these objects in the db.
My current workaround is to create a separate generator that inherits from SqlServerMigrationsSqlGenerator, override the Generate(SqlOperation operation...) method with the addition of batchBuilder.AppendLine(line) inside of the aforementioned if block, and replacing the IMigrationsSqlGenerator service with this new implementation via UseSqlServer().ReplaceService<>. However, it would be awesome to not have to do that as we're losing potential future optimizations of the generator and introducing potential for incompatibility and maintenance overhead for our future EF Core updates.
EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11 Pro 22H2
IDE: Visual Studio 2022 17.8.3
The text was updated successfully, but these errors were encountered:
We've upgraded to EF Core 8.0.0 (from 7.0.8) and have started experiencing an issue with
MigrationBuilder.Sql
where all empty lines are dropped from the SQL executed by the resulting migration. This seems to be a result of the change inSqlServerMigrationsSqlGenerator.Generate(SqlOperation operation...)
that was done to fix a regex timeout.In the current code, it seems that new
string.IsNullOrWhiteSpace(line)
check is causing this issue. Here's the related snippet from SqlServerMigrationsSqlGenerator:While some empty lines could be considered inconsequential, some are not, and currently all of them seem to be removed. For example, a migration like this:
Results in the below SQL execution (note the missing empty line):
Sample Code w/ Issue
Another of our current use cases involves using
MigrationBuilder.Sql
to manage changes to stored procedures and other db objects, and the dropped empty lines reduce readability of the definitions for these objects in the db.My current workaround is to create a separate generator that inherits from
SqlServerMigrationsSqlGenerator
, override theGenerate(SqlOperation operation...)
method with the addition ofbatchBuilder.AppendLine(line)
inside of the aforementionedif
block, and replacing theIMigrationsSqlGenerator
service with this new implementation viaUseSqlServer().ReplaceService<>
. However, it would be awesome to not have to do that as we're losing potential future optimizations of the generator and introducing potential for incompatibility and maintenance overhead for our future EF Core updates.EF Core version: 8.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11 Pro 22H2
IDE: Visual Studio 2022 17.8.3
The text was updated successfully, but these errors were encountered: