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

JSON: support for weakly typed json properties #28871

Open
maumar opened this issue Aug 24, 2022 · 2 comments
Open

JSON: support for weakly typed json properties #28871

maumar opened this issue Aug 24, 2022 · 2 comments

Comments

@maumar
Copy link
Contributor

maumar commented Aug 24, 2022

Currently we only support strongly typed POCO objects that map to JSON and are reflected in our metadata. We should also allow weakly typed properties, i.e. JsonDocument/JsonNode, that would not be reflected in our metadata and support query via GetProperty and various Get* methods (e.g. GetInt32) to retrieve the final scalar result.

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Apr 21, 2023

The Cosmos issue for this - #20584
Depends on #30604

We should consider exposing it through Dictionary<string, object> or any type with a compatible indexer property instead of depending on a specific DOM implementation.

@Ciantic
Copy link

Ciantic commented Oct 6, 2023

Postgresql's EF Core allows direct mapping with JsonDocument, e.g.

public class SomeEntity : IDisposable
{
    public JsonDocument Customer { get; set; }
}

JsonDocument is automatically recognized and mapped to jsonb

More details here: https://www.npgsql.org/efcore/mapping/json.html#jsondocument-dom-mapping

I would prefer these to be consistent, right now I'm writing a library that I would like to work with Postgresql and SQLite, I have to write HasConversion() with JsonDocument.WriteTo and Parse for the SQLite, if EF Core supported JsonDocument directly things would be more consistent.

JsonDocument has one drawback it is IDisposable, it makes all entities IDisposable as well, this is not what I would want though.

I think JsonNode could be a better value type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants