dotnet / dotnet/EntityFramework.Docs
HasConversion<string>() always returns "False"
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
## File a bug
Here's [the docs section](https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions?tabs=data-annotations#built-in-converters) that details the conversion options (`bool` is at the top).
### Include your code
Model:
```c#
public class MyModel
{
public bool IsTrue { get; set; }
}
```
Context:
```c#
modelBuilder
.Entity(eb =>
{
eb.HasNoKey();
eb.ToView("MyView");
eb.Property(v => v.IsTrue).HasColumnName("yes_no_value").HasConversion(); // this line always returns False
});
```
Changing the mapping/conversion line to the following works:
```c#
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
Contributor guide
Assessment
This issue has not been assessed yet.