-
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
NRE when adding entity with an owned entity and ToJson
configuration
#32288
Comments
@roji Is this just about a better exception when a mapped type doesn't have a JSON serializer? |
Ah yes, good catch. I added the JSON support to most type mappings in EFCore.PG after rc2 (npgsql/efcore.pg#2926). I've already added fixes to throw a better exception in #32255 (which needs to be completed). @markushaslinger can you please try Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0-rtm-ci.20231115T131924 from the daily build vNext feed, and report on how that works for you? You should be able to use that with EF 8.0.0 GA. |
@roji I tried, but the closest I could find for Npgsql was 8.0.0-rtm-ci.20231115T161454, so I used that.
Used packages are (updated in the sample project I shared as well):
|
@markushaslinger can you please take another look? I'm seeing the right version (20231115T131924) show up as the latest on the myget vnext feed. I've checked and that version already references EF 8.0.0. The exact version is important as things are moving pretty fast right now. |
Also, I recommend removing Npgsql from your csproj, allowing Npgsql.EntityFrameworkCore.PostgreSQL to bring in whatever version it was built against. That may be the reason for the MissingMethodException. |
Yeah, I had the right version of Npgsql.EntityFrameworkCore.PostgreSQL, but the wrong of Npgsql.
And that was exactly it, don't know why I started including all three references in the first place, but I then just continued doing so in all subsequent projects for no apparent reason. Anyway: looks good! SELECT s."Id", s."Name", s."ExamGrades"
FROM jsontest."Students" AS s
WHERE EXISTS (
SELECT 1
FROM ROWS FROM (jsonb_to_recordset(s."ExamGrades") AS (
"Date" date,
"Grade" integer,
"Subject" text
)) WITH ORDINALITY AS e
WHERE e."Date" > @__threshold_0)
LIMIT 1 I think this can be closed, my scenario is working fine at least. Thanks for patching it up so quickly! |
Great! Thanks for testing and confirming! |
@roji asked me to open this issue, might be a simple configuration error, though.
Scenario
A very bare bones console application I created to check out the new
ToJson
support in npgsql.Uses the following simple model to create and insert two students, then performs a query on the date field of the owned entity.
Mind that the owned entity contains a NodaTime type property.
Behavior
A
NullReferenceException
is thrown when callingSaveChanges
.Expected Behavior
No exception is thrown, entities are inserted and then queried successfully.
Exception
Reproduction
I pushed the project to this repo. It should be sufficient to clone and run to get the exception.
It is set up to use Postgres, but a quick test showed the same error when using SqlServer - which is why I'm opening the issue here and not in the efcore.pg repo.
Workaround
Defining a Converter using
JsonSerializer
allows the entities to be inserted and the query to be excuted, but the date column is of course treated asstring
and not asdate
.Sample in the repro project as well.
Provider and version information
EF Core version: 8.0.0-rc.2.23480.1
Database provider: PostgreSQL 8.0.0-rtm-ci.20231113T150204, SqlServer 8.0.0-rc.2.23480.1
Target framework: net8
Operating system: Win11 x64
IDE: Rider
NodaTime Compat: Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime 8.0.0-rtm-ci.20231113T150204, SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime 8.0.0-rc.2.23480.1
The text was updated successfully, but these errors were encountered: