-
Notifications
You must be signed in to change notification settings - Fork 225
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
Unable to specify naming policy when querying JSON fields #1134
Comments
@roji I'm wondering if you can give any guidance whether this is possible right now I'm trying to integrate with an existing db that I have to follow its conventions 🙏 |
I have the same problem using var mappingBuilder = new Npgsql.TypeMapping.NpgsqlTypeMappingBuilder
{
PgTypeName = "jsonb",
TypeHandlerFactory = new JsonbHandlerFactory(new JsonSerializerOptions
{
Converters = { /* ... */ },
DictionaryKeyPolicy = new SnakeCaseJsonNamingPolicy(),
PropertyNamingPolicy = new SnakeCaseJsonNamingPolicy()
}),
NpgsqlDbType = NpgsqlDbType.Jsonb,
ClrTypes = new[] { typeof(JsonDocument) }
};
Npgsql.NpgsqlConnection.GlobalTypeMapper.RemoveMapping("jsonb");
Npgsql.NpgsqlConnection.GlobalTypeMapper.AddMapping(mappingBuilder.Build()); As noted by the author of the issue, everything works fine while serializing to and deserializing from JSONB columns. I know the limitation is probably already known, just wanted to note that it doesn't seem to be specific of the JSON.NET integration. |
@giulianob I think you may be mixing JSON.NET and System.Text.Json. At the lower ADO level, Npgsql has a JSON.NET plugin (Npgsql.Json.NET), and 4.1 also added support for the new System.Text.Json (without any plugin). At the higher EF Core level, only System.Text.Json is supported for now, and there's unfortunately no support yet for configuring the naming policy (or any other serialization option). #1107 already tracks that, and I definitely see it as an important issue that we should do soon. @markron's answer can help for serialization/loading, but as they noted it doesn't take care of generating queries over JSON columns in the database (the solution is very similar to this one. Am closing this as a duplicate of #1107. |
I'm currently using JSON.NET and specifying a naming policy for snake case
I'm able to serialize/deserialize my JSON to/from a POCO just fine when doing simple read/writes to the db. However, when I'm trying to query a JSON field there's an issue. For example:
The query generated is as follow:
The issue is that my JSON is in snake case so I would expect it to generate the following instead:
Is there any configuration available to make this work?
The text was updated successfully, but these errors were encountered: