Closed olucafont6 closed 3 years ago
This doesn't repro for me with 5.0.10. Using the code sample below, which is based on your snippets above, I get the following SQL query:
SELECT r."Id", r.column1
FROM "Rows" AS r
WHERE r.column1->>'value-kebab-case' = 'foo'
LIMIT 1
Which version are you using? Can you tweak the code sample to make it fail, or submit your own minimal code sample?
@roji Oh, right. Yeah the project I'm using it from is only on .NET Core 3.1, so I was using 3.1.18. It's possible I could upgrade to .NET 5 if this works in the 5.x version of the library.
Can you try your reproducer with 3.1.18 and see if it still succeeds? If so, maybe I'm doing something wrong. I'll try creating a minimal reproducer also - not sure if I need an actual Postgres database for that.
Here, I think this is a reproducer for 3.1.18 - not sure if the LogTo()
function / extension method was available so I included some code I found online that will output the SQL query.
I get this output when I run it - let me know if it doesn't work for you.
SELECT r."Id", r.column1
FROM "Rows" AS r
WHERE r.column1->>'Value' = 'foo'
Duplicate of #1419
Yeah, this was implemented for 5.0. This isn't something I can really backport to 3.1, especially since it may breaking existing users of 3.1 depending on that behavior - you'll have to update to 5.0 or 6.0 (an rc2 of the latter is out, with the final release in around a month).
@roji Okay cool - yeah that's fine. I think I should be able to upgrade this project to .NET 5, and if not I can just use the explicit SQL query for now.
Is this feature (respecting JsonPropertyName
when generating a query from LINQ) in the documentation anywhere (I couldn't find it). Seems like it could be helpful for future readers, and there could be a disclaimer about it only starting in version 5.x.
Yeah, we could add a note on the JSON page - opened https://github.com/npgsql/doc/issues/131 to track.
YEAH YOUR RIGHT ROJI
Basically I'm trying to do something like this:
(This is a genericized version of my actual application code, but I didn't actually run it, so some of the details might be slightly off.)
I expected
FindMatchingEntry()
to essentially generate a request like this:But instead it generates something like this:
It's weird because specifying the JSON property name works when loading data into the class I created (
[JsonPropertyName("value-kebab-case")]
), but it doesn't seem to have any effect when translating a LINQ expression to a SQL query.I can manually specify the SQL query as a workaround (
FindMatchingEntryExplicitQuery()
), but it would be nice if the SQL method worked with custom JSON property names. Maybe I'm just missing something - I didn't see anything about it in the documentation though.Let me know if there's any other information I can provide - thanks!