EntityFramework.Docs
EntityFramework.Docs copied to clipboard
HasConversion<string>() always returns "False"
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
Confirmed this is a doc bug. The default bool to string conversion works with "0" and "1", not "N" and "Y".