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

Column that follows a JSON Path #33341

Closed
TonyValenti opened this issue Mar 16, 2024 · 3 comments
Closed

Column that follows a JSON Path #33341

TonyValenti opened this issue Mar 16, 2024 · 3 comments

Comments

@TonyValenti
Copy link

I have a bunch of JSON api results that I want to store in a database.

In my table, I want certain properties to always follow values in my json object this way I have direct, indexable access to certain json properties.

Does EFCore have a way to do this automatically or do I have to roll my own solution?

@roji
Copy link
Member

roji commented Mar 17, 2024

@TonyValenti I think you're looking for computed columns; e.g. for SQL Server you can define a computed column with the JSON_VALUE() function following a path in another column that contains JSON data.

@TonyValenti
Copy link
Author

This is almost exactly what I want, except this is SQL server specific.

Is there an overload that I can provide a func/expression that will allow me to tell EFCore "whenever adding/updating this object, recompute the value of this property with this C# expression"?

@roji
Copy link
Member

roji commented Mar 17, 2024

Is there an overload that I can provide a func/expression that will allow me to tell EFCore "whenever adding/updating this object, recompute the value of this property with this C# expression"?

No, there's nothing like that (tracked by #11001). However, you can easily check for the database provider being targeted (SQL Server vs. PG or whatever) and vary the computed column SQL definition.

@AndriySvyryd AndriySvyryd removed their assignment Apr 1, 2024
@AndriySvyryd AndriySvyryd closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants