Skip to content

Generates invalid SQL Server migrations script for computed stored with specific collation #31177

@AnderssonPeter

Description

@AnderssonPeter

File a bug

Include your code

I have the following migration

migrationBuilder.AddColumn<string>(
                name: "FullName",
                table: "Person",
                type: "nvarchar(1024)",
                maxLength: 1024,
                nullable: true,
                computedColumnSql: "RTRIM(LTRIM(CONCAT(COALESCE([FirstName] + ' ', ''), COALESCE([LastName] + ' ', ''))))",
                stored: true,
                collation: "SQL_Latin1_General_CP1_CI_AI");

And when I run update-database it generates the following SQL:

ALTER TABLE [Persons] ADD [FullName] AS RTRIM(LTRIM(CONCAT(COALESCE([FirstName] + ' ', ''), COALESCE([LastName] + ' ', '')))) PERSISTED COLLATE SQL_Latin1_General_CP1_CI_AI;

But it should generate

ALTER TABLE [Persons] ADD [FullName] AS RTRIM(LTRIM(CONCAT(COALESCE([FirstName] + ' ', ''), COALESCE([LastName] + ' ', '')))) COLLATE SQL_Latin1_General_CP1_CI_AI PERSISTED ;

Include provider and version information

EF Core version: 7.0.8 (All ef packages are 7.0.8)
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.6.4

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions