-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Compiled model with value converters #25187
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
regarding: I had the same issue on a ubuntu linux server running dotnet 6.0 Preview 2, after updating to Preview 5 the issue was gone. |
@Spacefish DateOnly is a new type which was only introduced in .NET 6.0 preview5. |
Appears to be fixed in 6.0.0-rc1 |
@AndriySvyryd what is the status on DateOnly & TimeOnly conversions in RC1? Do we still need to write custom converters for SQL Server? |
Yes, SQLClient doesn't natively support them yet, see dotnet/SqlClient#1009 |
I"m not seeing this fixed in 6 RC1.
|
@aherrick Use entity.Property(o => o.UsageLogType)
.HasMaxLength(10)
.HasConversion<EnumToStringConverter<UsageLogType>>(); |
I was unable to create a compiled model (#1906) if there was a custom value converter in the model. The problem is related to EF Core version 6.0 preview 5. EF Core tools (
dotnet ef
) are also version 6 preview 5. To reproduce the problem you can create an application (dotnet new web --name CompiledModelConverter
), install preview 5 versions ofMicrosoft.EntityFrameworkCore.SqlServer
andMicrosoft.EntityFrameworkCore.Design
and replace the content ofStartup.cs
with the following code:Now running the command
dotnet ef dbcontext optimize --verbose
produces the following error:I tried replacing the converter configuration as suggested in the issue #1906 with the following code:
Now running the same command produces the following error:
Removing the conversion configuration all together results in a successful generation of compiled model. So does using a generic overload of
HasConversion
method without specifying a converter, for example:Using one of the built in converters such as
StringToBoolConverter
does not work, it produces same error as a custom value converter.I have tried this with SQL Server and SQLite and behavior is the same.
I have also tried using PostgreSQL but I get the following error whether I have value converters configured or not:
Could not load type 'System.DateOnly' from assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I suppose that PostgreSQL error is related to something else or I might have misconfigured something (I only installed
Npgsql.EntityFrameworkCore.PostgreSQL
and replaced.UseSqlServer
with.UseNpgsql
). I decided to metionEF Core version: 6.0 preview 5
Database provider: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.SqlLite
Target framework: .NET 6.0 preview 5
Operating system: Windows 10
IDE: VS Code
The text was updated successfully, but these errors were encountered: