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

Query: Change JsonQueryExpression.Path to be a List<PathSegment> #28836

Closed
smitpatel opened this issue Aug 22, 2022 · 6 comments · Fixed by #28888
Closed

Query: Change JsonQueryExpression.Path to be a List<PathSegment> #28836

smitpatel opened this issue Aug 22, 2022 · 6 comments · Fixed by #28888
Assignees
Labels
area-json area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@smitpatel
Copy link
Contributor

Where PathSegment can be either
KeyAccess which is string joined using .
ArrayAccess which is SqlExpression using []
Or random string which we would just append, in case provide wants to add more fancier thing.

It cannot be SqlExpression even though SQL syntax allows it because neither user can write a LINQ query which accesses an arbitrary key on an object using column/parameter nor we can translate it because we need metadata of the bound property in order to materialize.

@roji
Copy link
Member

roji commented Aug 22, 2022

It cannot be SqlExpression even though SQL syntax allows it because neither user can write a LINQ query which accesses an arbitrary key on an object using column/parameter nor we can translate it because we need metadata of the bound property in order to materialize.

I'm not sure how much we're designing with weakly-typed JSON mapping in mind... But if so, then the above is definitely possible (and important). For example, the PG provider supports the following:

_ = ctx.JsonEntities.Single(e => e.CustomerElement.GetProperty("Name").GetString() == "Joe");

... where GetProperty is an expression-based way to access arbitrary properties (or keys) on JSON elements (it could even be a column expression). We may not allow materializing the result, but at the very least if the query represents a scalar we can read it back or generate a SQL expression that compares it to something, as above.

But maybe you have something else in mind for when we implement weakly-typed JSON...

@smitpatel
Copy link
Contributor Author

weakly-typed JSON mapping

Weakly-typed JSON doesn't work in EF Core metadata. We cannot translate it and generate metadata for materializing. Bottom-line is weakly-typed JSON, even if we support it cannot use any of the code we have added for now. Let's not ruin the design for the sake of something which will never use the design in first place.

@roji
Copy link
Member

roji commented Aug 22, 2022

Up to you, of course. JsonQueryExpression specifically looks like it should be usable for weakly-typed, since it simply expresses traversal... But we can deal with it later, as you wish.

@smitpatel
Copy link
Contributor Author

Well JsonQueryExpression contains IEntityType, it cannot support weakly-typed.

@smitpatel
Copy link
Contributor Author

In future if we add support for weakly-typed, we could create expression to support weakly-typed and use wrapper over it in place of current expressions we use to add additional metadata.

@roji
Copy link
Member

roji commented Aug 22, 2022

Makes sense.

@smitpatel smitpatel added this to the 7.0.0 milestone Aug 23, 2022
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 25, 2022
smitpatel added a commit that referenced this issue Aug 25, 2022
smitpatel added a commit that referenced this issue Aug 25, 2022
smitpatel added a commit that referenced this issue Sep 8, 2022
smitpatel added a commit that referenced this issue Sep 8, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-rc2 Sep 9, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-rc2, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-json area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants