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

SQL_Latin1_General_CP1_CS_AS is not generate a valid code to Update-Database #24820

Closed
Ali-YousefiTelori opened this issue May 1, 2021 · 3 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@Ali-YousefiTelori
Copy link
Contributor

When I try to add

modelBuilder.Entity(entity)Property(x=>x.UniqueRecordId).HasColumnType("NVARCHAR(4000) COLLATE SQL_Latin1_General_CP1_CS_AS")

to my model builder my migration will add this line:

migrationBuilder.CreateTable(
                name: "ObjectIds",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ObjectId = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ModificationDateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreationDateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Key = table.Column<string>(type: "nvarchar(450)", nullable: true),
                    UniqueRecordId = table.Column<string>(type: "NVARCHAR COLLATE SQL_Latin1_General_CP1_CS_AS(4000)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ObjectIds", x => x.Id);
                });

But the generated code is not valid.
instead of this line:

UniqueRecordId = table.Column<string>(type: "NVARCHAR COLLATE SQL_Latin1_General_CP1_CS_AS(4000)", nullable: true),

Must changed to:

UniqueRecordId = table.Column<string>(type: "NVARCHAR(4000) COLLATE SQL_Latin1_General_CP1_CS_AS", nullable: true),

To works for Update-Database.

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 5.0.2)
Operating system:
IDE: (e.g. Visual Studio 2019 16.9.1)

@roji
Copy link
Member

roji commented May 1, 2021

Rather than specifying the collation as part of the column type, have you tried using the dedicated EF API for specifying the collation separately?

@Ali-YousefiTelori
Copy link
Contributor Author

Ali-YousefiTelori commented May 2, 2021

@roji Thank you this way working, but ew problem I got and I think it's a bug. After add migration I see this code:

            migrationBuilder.AlterDatabase(,
                oldCollation: "SQL_Latin1_General_CP1_CI_AS");

I changed it to:

            migrationBuilder.AlterDatabase(null,
                oldCollation: "SQL_Latin1_General_CP1_CI_AS");

And It's fixed now.

@roji
Copy link
Member

roji commented May 2, 2021

@Ali-YousefiTelori that looks like #23794, which was fixed in 5.0.2. It's always recommended to use the latest patch version.

@roji roji added the closed-no-further-action The issue is closed and no further action is planned. label May 2, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants