Skip to content
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

Provide EF.Functions translations for JSON functions #29306

Open
roji opened this issue Oct 10, 2022 · 8 comments · May be fixed by #30010
Open

Provide EF.Functions translations for JSON functions #29306

roji opened this issue Oct 10, 2022 · 8 comments · May be fixed by #30010

Comments

@roji
Copy link
Member

roji commented Oct 10, 2022

For users using JSON without a strongly-typed schema, mapping the column as a string is the only option at the moment. We should provide translations for JSON_VALUE/JSON_QUERY for SQL Server and json_extract for SQLite.

@joelmandell
Copy link

If this is up for grabs I might look into it @roji

@roji
Copy link
Member Author

roji commented Jan 4, 2023

@joelmandell sure, go ahead - the "good first issue" label is a good indication that it's a relatively accessible issue that external contributors can work on (but always good to check).

@joelmandell
Copy link

Hi @roji,
I tried to add an IMethodCallTranslator for JSON_VALUE for the SqlServer provider. But the Translate() method is never called. I am having a hard time finding out why it is not being picked up. Do you have anything that can point me to in the correct direction?

@roji
Copy link
Member Author

roji commented Jan 7, 2023

Have you added your method call translator to SqlServerMethodCallTranslatorProvider?

@joelmandell
Copy link

joelmandell commented Jan 7, 2023

Yes @roji . I have added it there. But I am missing something else :)
This is how it is currently joelmandell@0a81a96

@roji
Copy link
Member Author

roji commented Jan 7, 2023

I can't see anything immediately wrong with that code, what does debugging through it show? Does it maybe get into your method translator but doesn't recognize the method?

@joelmandell
Copy link

joelmandell commented Jan 7, 2023

Okay my bad. I did some stupid stuff @roji
I did this: ss.Set<JsonEntityBasic>().Where(c => EF.Functions.JsonValue(c.OwnedReferenceRoot, "$.Name") == "foo")
OwnedReferenceRoot is not a string but an complex property on the JsonEntityBasic class.

When I did an EF.Functions.JsonValue with a string property i.e. c.MyStringWithJson, it works.

@roji
Copy link
Member Author

roji commented Jan 8, 2023

Makes sense.

We could have the function accept a string parameter - this would prevent this kind of mistake. On the other hand, it's probably fairly common for users to use value converters to convert some user object to a string, and they may wish to call JsonValue over that (and having an object allows that).

In theory, it would be nice if users could even invoke this function over an EF7 JSON column property (i.e. an owned entity type); but that likely requires some more significant infrastructure changes to support.

In any case, I suggest leaving as-is for now (with object). When you submit your PR, I'll discuss that with the team.

@joelmandell joelmandell linked a pull request Jan 10, 2023 that will close this issue
6 tasks
roji pushed a commit to joelmandell/efcore that referenced this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants