question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow mapping JSON to Dictionary<string,string>

See original GitHub issue

Hello! I have question. I used next entity with jsonb type column:

class Entity
{
    public int Id {get;set;}
    
    [Column(TypeName = "jsonb")]
    public Dictionary<string, string> Name {get;set;}  
}

I want to use order by for example how Postgres SQL script:

SELECT "Id", "Name" FROM public."Entities" ORDER BY "Name"->>'en' DESC

Is it possible to do this sorting on EF? I searched in the documentation for this, as well as on the vastness of stackoverflow and in issues github, but I did not find an answer to this question.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Apr 26, 2021

The provider currently doesn’t support mapping Dictionary<string,string> to JSON; you can either map a .NET POCO (for strongly-typed documents with a fixed schema) or JsonDocument (for weakly-typed documents with varying schemas). See the docs for more details. If you use one of these two mapping techniques, you can generate a JSON field lookup in an ORDER BY just as you would in a WHERE clause.

Keeping open to track mapping Document<string,string>.

0reactions
rojicommented, Aug 7, 2023

Yep - that should take care of serialization. The only thing this doesn’t take care of is querying (e.g. filtering based on the value inside the dictionary).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I deserialize JSON to a simple Dictionary<string ...
Just send JSON string in to deserializeToDictionary function it will return non strongly-typed Dictionary<string, object> object. Old code
Read more >
Convert a JSON String to a Dictionary in Python
To convert a JSON string to a dictionary in Python, you can leverage the “JSON” module and its “loads()” function. By passing the...
Read more >
json string to dictionary
I have a simple json string {"1":10,"2":25,"3":1,"4":124,"7":567} I have a Dictionary Dictionary Gameitems = new Dictionary ();...
Read more >
How do I create JSON Object from Dictionary(String, String)
I want to translate pairs from dictionary (Key:Value) given like this or otherwise transparently: to this: Where “fields” is main object, ...
Read more >
How to Map Nested JSON Objects to a .NET Dictionary
How to Map Nested JSON Objects to a .NET Dictionary. Sometimes a public JSON API responds in a format that you can't control....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found