Quantcast
Channel: User Victor Ronin - Stack Overflow
Viewing all articles
Browse latest Browse all 40

How to map fields name in jsonb field to another name in object?

$
0
0

I use Postgres and I have DB with a table that looks like that

column - footype - jsonbvalue - {"baz" : "test" }

Please notice that "baz" is not capitalized (pretty much this json document will be in a camelCase).

I have the code in C# (so the naming convention is Pascal Case)

public class Foo{     [Column(TypeName = "jsonb")]     public BarData Bar { get; set; }}public class BarData{   // ??? What kind of annotation to put here   public String Baz { get; set; }}

I use entity framework + npgsql to read/write to DB. Unfortunately, when npgsql read from DB, it won't populate Baz (because the naming convention doesn't match)

a) I tried to use [Column("baz")]. However, it's ignored (probably because it's not really a column, but a json tag)

b) I was considering naming the property "baz", but it just shifts a problem to another place in the code (where another mapping needs to be done).

As a result, I am looking whether I missed some way to do it case-insensitive or map the property to the name which comes from json.


Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>