Efcore.pg: Is there any plan for supporting nullable JsonElements?

Created on 22 Jul 2020  路  5Comments  路  Source: npgsql/efcore.pg

If not is there any interest this functionality? I'd be happy to work on it.
An example use case would be this:

public class Entity {
    public JsonElement? Property { get; set; }
}

var johns = context.Entities.Where(e => e.HasValue && e.Value.GetProperty("name").GetString() == "john");

You can currently work around this with the JsonExists extensions and an explicit cast, but it would be nice to have.

All 5 comments

@tommymh this should be working just as int? properties should be working, what exact issue are you seeing with this? JsonExists should only be for JSON properties within the document, not for top-level properties on EF entity types...

@roji thanks for the reply, I am actually using JsonExists to verify that a property inside the top level document exists, so that I can be sure it isn't null(not ideal, I know). The error I'm getting is that the query can't be translated to SQL and I should try client side evaluation, or something to that effect. I will try to remove my application specific business logic and put an example repo together that can reproduce the issue.

@tommymh any luck with that repro?

Sorry @roji I have been pretty busy lately. I fully intend to provide a repo for this bug(if it turns out to be a bug), so if you don't mind leaving this issue open, I can do it here. Would a repo with a docker-compose be the most helpful, or would you like to set up your environment yourself with just the .net core project?

@tommymh a simple console program is most helpful, which either sets up its own database or with an accompanying SQL script that does that (please try to keep it as minimal as possible, grokking through big repro projects is difficult).

I'm going to close this for now (because otherwise it shows up as an untriaged issue for us), but the moment you post back a repro I'll reopen and investigate.

Was this page helpful?
0 / 5 - 0 ratings