-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Milestone

Description
Describe what is not working as expected.
If you have a nullable enum property that also uses a value converter, the snapshot code generates invalid calls.
public enum RoadwaySides
{
Left = -1,
Center,
Right
}
public class ProjectDetail
{
public RoadwaySides? RoadwaySide { get; set; }
}
... in model builder
builder.Property(pd => pd.RoadwaySide).HasConversion(v => v == RoadwaySides.Left ? "L" : v == RoadwaySides.Center ? "C" : v == RoadwaySides.Right ? "R" : null, v => v == "L" ? RoadwaySides.Left : v == "C" ? RoadwaySides.Center : v == "R" ? RoadwaySides.Right : (RoadwaySides?)null).HasColumnName("RDWYSIDE").HasColumnType("char(1)").HasMaxLength(1);
... in generated snapshot
b.Property<int?>("RoadwaySide")
.HasConversion(new ValueConverter<RoadwaySides?, string>(v => default(string), v => default(RoadwaySides?)))
.HasColumnName("RDWYSIDE")
.HasColumnType("char(1)")
.HasMaxLength(1)
.IsUnicode(false);
The snapshot generator unwraps the enum for the property call but does not unwrap the enum for the HasConversion call.
I think this line:
https://github.com/aspnet/EntityFrameworkCore/blob/dev/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs#L433
needs a .UnwrapEnumType() call in it to fix the problem.
Further technical details
EF Core version: 2.1.0 - 28148
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win10 Ent
IDE: Visual Studio comm 2017 15.4