EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

HasConversion<string>() always returns "False"

Open mrlife opened this issue 3 years ago • 1 comments

File a bug

Here's the docs section that details the conversion options (bool is at the top).

Include your code

Model:

public class MyModel
{
    public bool IsTrue { get; set; }
}

Context:

modelBuilder
.Entity<MyModel>(eb =>
{
    eb.HasNoKey();
    eb.ToView("MyView");
    eb.Property(v => v.IsTrue).HasColumnName("yes_no_value").HasConversion<string>(); // this line always returns False
});

Changing the mapping/conversion line to the following works:

eb.Property(v => v.IsTrue).HasColumnName("yes_no_value").HasConversion(new BoolToStringConverter("N", "Y"));

Include provider and version information

EF Core version: 5.0.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 5.0 Operating system: macOS 11.4 IDE: Visual Studio for Mac 8.10 build 10

mrlife avatar Jul 20 '21 20:07 mrlife

Confirmed this is a doc bug. The default bool to string conversion works with "0" and "1", not "N" and "Y".

ajcvickers avatar Jul 26 '21 09:07 ajcvickers