Skip to content
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

Support for EF core 7.0 ToJson() (owned entity JSON modeling) #2548

Closed
cluka opened this issue Oct 27, 2022 · 9 comments
Closed

Support for EF core 7.0 ToJson() (owned entity JSON modeling) #2548

cluka opened this issue Oct 27, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@cluka
Copy link

cluka commented Oct 27, 2022

Hi,
I am trying to use the new EF core 7.0.* ToJson method to map my entity to a json column.
And When I do migration, I get "Sequence contains no elements" in Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal.NpgsqlAnnotationProvider.For(IColumn column, Boolean designTime)+MoveNext()

Is this supported and if not, will it be?

Thanks

@roji
Copy link
Member

roji commented Oct 30, 2022

The Npgsql provider will not be supporting EF's new ToJson in version 7.0, but we plan to enable this in version 8.0 and converge JSON support.

The Npgsql provider has had its own support for a long time, and while the EF support is based on owned entities (and will therefore unlock partial updates in the future), the Npgsql support is based on simple type mapping instead. Unfortunately, the EF 7.0 feature won't support everything that Npgsql currently supports (e.g. weakly-typed mapping via JsonDocument).

Note that for 7.0 GA, ToJSON is specifically blocked in model validation when using the Npgsql provider, to make sure users understand the different in JSON support (see #2452). Keeping this issue to track supporting EF's ToJson in 8.0.

@markushaslinger
Copy link

There are already preview versions for .NET 8 on NuGet, but I didn't find a branch or release notes on what those contain. I suppose the JSON support is still not in?
Do you still plan to integrate it in the next couple weeks, or has that work been postponed for .NET 9?

@roji
Copy link
Member

roji commented Aug 10, 2023

@markushaslinger I absolutely do intend to do this for 8.0, but the PG work has been delayed for now (that's also why there aren't yet later preview versions). But this is something I'll be tackling in the coming weeks, I hope you'll be able to use a fully functional rc1 release including ToJson() support.

@hrytskivr
Copy link

Hi, @roji, rc1 is out. Did you implement that thing and if so where I can find docs?

@roji
Copy link
Member

roji commented Sep 17, 2023

@hrytskivr I did not.

@diagorasnicolaides
Copy link

@roji great stuff. If you get an indication on when this might be out let us know. Super excited to use this!

@roji
Copy link
Member

roji commented Oct 5, 2023

Everyone, I've unfortunately been very busy with high-priority work, and did not get to this yet; this feature won't yet be available in 8.0.0-rc.2 which is coming out next week. However, it will be one of my top priorities for getting done for the actual 8.0.0 release. It isn't good to add a feature so late, but it's better than nothing...

@roji roji closed this as completed in 4a7ef97 Nov 6, 2023
@roji roji changed the title Support for EF core 7.0 ToJson() Support for EF core 7.0 ToJson() (owned entity JSON modelling) Nov 13, 2023
@roji roji changed the title Support for EF core 7.0 ToJson() (owned entity JSON modelling) Support for EF core 7.0 ToJson() (owned entity JSON modeling) Nov 13, 2023
@alvanrahimli
Copy link

Hello. I am sorry, I didn't know where is the good place to post this question.
Is it safe to just replace all .HasColumnType("jsonb") calls in OnModelCreating with OwnsOne(.... ToJson()) calls?

@roji
Copy link
Member

roji commented May 17, 2024

@alvanrahimli that depends on what exactly you're doing with those columns - certain things may not work. I'd recommend trying to migrate gradually and carefully testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants