Update-Database will output SQL that has incorrect newlines
MikeDPeterson opened this issue · comments
If a migration uses \n or \r instead of \r\n for a newline, the SQL after the \n will be output to the command window
Steps to reproduce
Create a migration that does some SQL. This can be an INSERT, UPDATE, or SELECT statement
For example
public partial class NewLineDemo : DbMigration
{
public override void Up()
{
// this gets outputted to console
Sql( "BEGIN\nSELECT [Id] FROM [Person]\nEND" );
// this gets outputted to console
Sql( "BEGIN\nSELECT [Id], [FirstName] FROM [Person]\nEND" );
// this does not get outputted to console
Sql( $"BEGIN{Environment.NewLine}SELECT [Id], [FirstName], [LastName] FROM [Person]{Environment.NewLine}END" );
// this does not get outputted to console
Sql( @"
BEGIN
SELECT [Id], [FirstName], [LastName], [BirthDate] FROM [Person]
END" );
// this get outputted to console
Sql( "BEGIN\nSELECT [Id], [FirstName], [LastName], [Email] FROM [Person]\nEND" );
}
public override void Down()
{
}
}
now do Update-Database and you'll see the SQL that uses just \n output to the package manager console
PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [202202152130544_NewLineDemo].
Applying explicit migration: 202202152130544_NewLineDemo.
SELECT [Id] FROM [Person]
END
SELECT [Id], [FirstName] FROM [Person]
END
SELECT [Id], [FirstName], [LastName], [Email] FROM [Person]
END
Running Seed method.
PM>
Further technical details
EF version: EF6.4.4
Database Provider: SQL Server
Operating system: Windows 10
IDE: Visual Studio 2019 16.11.7
This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.