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

Linq queries works with Ulid and throws with ExecuteSqlInterpolatedAsync #2259

Closed
juchom opened this issue Feb 2, 2022 · 1 comment
Closed

Comments

@juchom
Copy link
Contributor

juchom commented Feb 2, 2022

I'm using Ulid with EF Core and everything works fine when I use linq queries but the application throws an error when I use the ExecuteSqlInterpolatedAsync

I have this DbContext

public class ApplicationDbContext : DbContext
{
    protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
    {
        configurationBuilder.Properties<Ulid>()
            .AreUnicode(false)
            .AreFixedLength(true)
            .HaveMaxLength(26)
            .HaveConversion<UlidToStringConverter>();
    }
}

The converter

internal class UlidToStringConverter : ValueConverter<Ulid, string>
{
    public UlidToStringConverter()
        : base(
            convertToProviderExpression: x => x.ToString(),
            convertFromProviderExpression: x => Ulid.Parse(x))
    {
    }
}

This query throws

        var id = Ulid.NewId();
        await ApplicationAdminDbContext.Database.ExecuteSqlInterpolatedAsync(@$"
UPDATE app.""Roles""
SET ""Name"" = {name}
WHERE ""Id"" = {id}");
Unhandled exception rendering component: The current provider doesn't have a store type mapping for properties of type 'Ulid'.
System.InvalidOperationException: The current provider doesn't have a store type mapping for properties of type 'Ulid'.

This query works

        var id = Ulid.NewId();
        var idForSql = id.ToString();

        await ApplicationAdminDbContext.Database.ExecuteSqlInterpolatedAsync(@$"
UPDATE app.""Roles""
SET ""Name"" = {name}
WHERE ""Id"" = {idForSql}");

Do you have any idea why is this happening and how should I solve that ?

Thanks a lot.

@roji
Copy link
Member

roji commented Feb 3, 2022

@juchom this seems like a current EF Core limitation. I've opened dotnet/efcore#27354 to track this, and will update the docs to add this limitation.

@roji roji closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants