Skip to content

Migrations containing strings with many line-breaks will truncate strings silently #27206

@btastic

Description

@btastic

Description

This was originally filed in #24112 and got fixed in #24944.

We first found out about this issue when inserting a large legal text into our database, which contains a lot of line breaks. EF Core generates a large script which uses CONCAT() with up to 254 arguments, before starting a new CONCAT(). (\r and \n get converted to nchar(10) and nchar(13) and will be concatenated with the rest of the text)

As in #24112 described, there is an issue with CONCAT if you don't CAST the first parameter as nvarchar(max) the sql server will assume the 4000 byte limit.

This was fixed with #24944 by adding a CAST to the first parameter of CONCAT. However, subsequent CONCATs will not use a CAST. This will lead to silently truncated strings in the database.

I already had a look at the code and decided to fix it and contribute to this project.

if (concatCount == 254)
{
lastConcatStartPoint = builder.Length;
concatCount = 1;
}
}

It seems that resetting the castApplied flag to false inside the if fixes the issue.

As per the the contribution guidelines, I am requesting permission to file a PR.

Include provider and version information

EF Core version: latest (main branch)
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10
IDE: (e.g. Visual Studio 2019 16.3)

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions