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

Complex type with sparse columns leads to incorrect migration code. #34578

Closed
Poltuu opened this issue Aug 30, 2024 · 2 comments
Closed

Complex type with sparse columns leads to incorrect migration code. #34578

Poltuu opened this issue Aug 30, 2024 · 2 comments
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@Poltuu
Copy link

Poltuu commented Aug 30, 2024

EF.Core Migrations generates incorrect code when using IsSparse() on a column of a complex type.

The following configuration

builder.ComplexProperty(e => e.Address, p =>
{
   p.Property(n => n.PostalCode).HasMaxLength(10).IsSparse();
});

leads to the following code generation

    b.ComplexProperty<Dictionary<string, object>>("Address", "Employees.Models.PersonalRecord.Address#Address", b1 =>
        {

            b1.Property<string>("PostalCode")
                .HasMaxLength(10)
                .HasColumnType("nvarchar(10)");

            SqlServerPropertyBuilderExtensions.IsSparse(b1.Property<string>("PostalCode")); //<- error here
        });

Which fails with the following error during compilation
cannot convert from 'Microsoft.EntityFrameworkCore.Metadata.Builders.ComplexTypePropertyBuilder<string>' to 'Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder'

Include provider and version information

EF Core version: EF 8.0.8
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Visual Studio 2022

@AndriySvyryd
Copy link
Member

The workaround is to manually replace SqlServerPropertyBuilderExtensions.IsSparse with SqlServerComplexTypePropertyBuilderExtensions.IsSparse

@AndriySvyryd AndriySvyryd added this to the 9.0.0 milestone Aug 30, 2024
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 31, 2024
@AndriySvyryd AndriySvyryd removed their assignment Aug 31, 2024
@cincuranet
Copy link
Contributor

Miss clicked. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

3 participants