Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotent Migrations on HasDefaultValueSql or HasComputedColumnSql with line breaks adds whitespace #20391

Open
Tracked by #22946
lajones opened this issue Mar 23, 2020 · 1 comment

Comments

@lajones
Copy link
Contributor

lajones commented Mar 23, 2020

If the user creates a model using HasDefaultValueSql(xyz) and the string xyz has line breaks in it, and if the user produces an idempotent SQL script by using Script-Migration -Idemptotent, then extra spaces are added to the value they passed in. E.g. if they call

HasDefaultValueSql("'Don't
GO
this way'")

then the SQL generated will look like this:

IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'some_migration_identifier')
BEGIN
    CREATE TABLE [TestEntity] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(max) NULL DEFAULT N'Don''t
    GO
    this way',
        CONSTRAINT [PK_TestEntity] PRIMARY KEY ([Id])
    );
END;

Note that, because of the indentation, extra spaces have been added before 'GO' and 'this way'.

Similarly for HasComputedColumnSql().

But note: there is a workaround - the user can pass the following instead:

HasDefaultValueSql("CONCAT('Don't, CHAR(13), CHAR(10), 'GO', CHAR(13), CHAR(10), 'this way')")
@ajcvickers
Copy link
Member

Team discussion: consider warning in model validation. (Can warn for any new-line in the SQL; no need to only warn when it is in a literal.) Seems low priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants