No translation for dictionary indexer on jsonb columns
See original GitHub issueConsider the following entity:
public class User
{
[Key]
public Guid Id { get; set; }
[Column(TypeName = "jsonb")]
public Dictionary<string, object> Properties { get; set; }
}
And then querying:
context.User.Where(x => x.Properties["something"] == "something else").ToList();
Ends up not being able to translate.
Translating the method call of get_Item
to something npgsql can understand has proven to be difficult. And one would assume translating it into the proper binding is not possible due to the dynamic nature. I would assume some internal work is needed to properly translate get_Item
into sql directly instead.
I looked into perhaps doing a custom Visitor to handle this case but my Expression knowledge lacks in this case and it does not seem possible in the end anyways.
Also to clarify, changing the dictionary to a JsonDocument
type is not warranted in this case.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Indexing of tuples in a large PSQL JSONB array
I have a JSONB column "deps" like this ... Is it possible to create an index of the items by "name" field of...
Read more >JSONB PostgreSQL: How To Store & Index JSON Data
In this post, we are going to show you tips and techniques on how to effectively store and index JSON data in PostgreSQL....
Read more >Postgresql index for jsonb array field
One problem with document types like jsonb : Postgres currently does not maintain statistics about value frequencies of embedded elements (still ...
Read more >JSON Mapping | Npgsql Documentation
The Npgsql EF Core provider allows you to map PostgreSQL JSON columns in three different ways: As simple strings; As strongly-typed user-defined types...
Read more >PostgreSQL and JSON – How to Use JSON Data in ...
Here's an example of creating a Table Journal and giving the column “diary_information” the data type JSONB. CREATE TABLE journal ( id Int...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the added details. Yeah, mapping
Dictionary<string, object>
and translating the indexer seems like a very valid scenario to me - I’ve noted it for 6.0 (I’ll probably be doing work on this in EF itself). Jsonpath is definitely also on my list, tracked by https://github.com/npgsql/efcore.pg/issues/1045 for PG specifically - but again I’ll look into this from a cross-database perspective for 6.0.Will keep this open for now to specifically track dictionary indexer for EFCore.PG.
This is indeed unsupported at the moment. The mapping itself works since System.Text.Json can serialize/deserialize dictionary as JSON, but the query pipeline does not support the translating of the dictionary indexer, as you’ve noticed. There’s nothing impossible or special about it - just like we translate the various methods on JsonDocument, it’s possible to translate this.
We are planning a general JSON overhaul for EF Core 6.0 - not just for the PostgreSQL provider - so at this point I’m a bit reluctant to make this change. Is there any specific reason you don’t want to use JsonDocument, except for aesthetics?