Closed rlgordey closed 3 years ago
@rlgordey The key part about this message is the word "type" in, "Use 'HasConversion' to configure the value converter type." This means you need to create a ValueConverter type and configure that type in the model, rather than using inline conversion expressions. We will try to make this exception message clearer.
@ajcvickers I have tried ...
var converter = new ValueConverter<string, string>(
v => v.PadRight(15),
v => v.TrimEnd());
modelBuilder.Entity<Customer>()
.Property(e => e.Custnmbr)
.HasConversion(converter);
With the same error.
@rlgordey Hopefully this is clearer:
The property 'Customer.Custnmbr' has a value converter configured using a ValueConverter instance or inline expressions.
Instead, create a type that inherits from ValueConverter and use 'HasConversion<ConverterType>()' or
'HasConversion(Type converterType)' to configure the value converter.
I have a Customer Entity configured in my DbContext.ModelBuilder as:
The entity that was scaffolded is:
When I run
Optimize-DbContext
I get this exception:Even though it is using 'HasConversion'.
EF Core version: 6.0.0-rc.2.21426.10 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: net6.0 Operating system: Windows 10 IDE: Visual Studio 2022 17.0.0 Preview 3.1