-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom ValueConverter doesn't get translated to SQL #11156
Comments
Also, I see in the docs:
However, I do not see any such warnings. |
@mj1856 Yes, this is a limitation of value converters that we are tracking with #10434. We are going to add the warning before 2.1 RTM, but it hasn't been done yet. We hope to add a mechanism to allow translation in a later release. We had discussed here the idea of using this to support NodaTime. Very interested to see how it goes and hear any feedback you have. /cc @divega @roji |
Note that the next version of PostgreSQL/Npgsql will support Nodatime at the ADO.NET level (in fact, this should become the recommend way to do date/time), removing the need to do this at the EF Core level with value converters. However, when it comes to translating operations, the same problem exists - translators have to be done for operations on Nodatime types, npgsql/efcore.pg#300 tracks that for Npgsql. |
Just ran into this as well. Was hoping to be able to use NodaTime in our domain models but sadly it looks like we won't be able to yet at this point :( |
For anyone else that comes across this thread, it looks like Npgsql 4.0 (released May 31, 2018) adds support for NodaTime if you are using a PostgreSQL database. Rather than use custom ValueConverters (which loads the entire table to do client-side evaluation of WHERE clauses), queries are translated to SQL statements. |
@ajcvickers This issue is still with the latest version of EF Core. I see a warning, but cannot filter resultset by NodaTime's LocalDate/LocalDateTime/Instant
Are any plans to implement this in further releases, or at least ability how to help SqlTranslator to do that? I tried to add SqlColumnType for an EntityTypeBuilder
Thank you. |
FYI - For those using SQL server, I have published a package adding native support for NodaTime types here. It is still very early but it should provide basic support for the following types:
The repo can be found here for reporting any issues. I appreciate any feedback from the community and hope that one day MS will provide this OOB. |
I'm trying out the new
ValueConverter
type in the 2.1 preview. I plan to use this to author a library to support using NodaTime types in EF Core. I'm starting this experiment by trying to store aNodaTime.Instant
type as a UTC-basedDateTime
into a SQL Serverdatetime2
field.My Model:
I then create the migration script, init the database, add some values, etc. All works reasonably well until I go to query.
This works and gives back the correct results, but if I use SQL Profiler to examine the query, I see:
It did not include a
WHERE
clause in the translation, resulting in a full table select. I assume it then filters the results in memory. This would be bad on a large table.My understanding is that it should be able to invoke the
ValueConverter
, translate the expression to one that is based onDateTime
, allowing the SQL provider to write theWHERE
clause - but this doesn't seem to be happening.When I try the same thing using the built-in
DateTimeToStringConverter
, it does include aWHERE
clause. Looking at the implementation of that class, I don't see anything special as compared to any otherValueConverter
, so I'm not sure what's going on.The text was updated successfully, but these errors were encountered: