Open ADD-David-Antolin opened 1 month ago
Minimal repro:
await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var wrapper = new MyWrapper(8);
_ = await context.Blogs.Where(p => wrapper == p.Id).ToListAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.DefaultTypeMapping<MyWrapper>().HasConversion<MyWrapperConverter>();
}
private class MyWrapperConverter() : ValueConverter<MyWrapper, int>(v => v.Wrapped, v => new MyWrapper(v));
}
public class Blog
{
public int Id { get; set; }
}
public record MyWrapper(int Wrapped)
{
public static bool operator ==(MyWrapper left, int right) => left.Wrapped == right;
public static bool operator !=(MyWrapper left, int right) => left.Wrapped != right;
}
File a bug
Include your code
DefaultTypeMappingsTests.zip
Change between SqlServer and Sqlite by modifying the method called in line 6.
Include stack traces
SqlServer:
Sqlite:
Include provider and version information
EF Core version: Database provider: Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Sqlite Target framework: .NET 8.0 Operating system: Windows 10 & 11 IDE: Visual Studio 2022 17.11.4