[release/7.0] Fix to #29355 - FromSqlRaw throws Exception when querying all objects that contain a certain string property in a json array column #29366
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem was that were not creating navigation bindings for JSON entities in the SelectExpression ctor which takes TableExpressionBase as argument. This would cause error in SharedTypeEntityExpandingExpressionVisitor which depends on those bindings to be present for entities mapped to JSON.
Fix is to use the same logic we use in the "main" SelectExpression ctor.
Fixes #29355
Customer impact
All queries using FromSql on entities that contain owned types mapped to JSON fail with NRE. FromSql is not the mainline scenario for JSON, but it could be used to work-around limitations in our JSON query translation capabilities, which is important given that there are quite a few limitations for JSON in the EF7 release. This issue effectively prevents the customers from using the workaround to unblock their scenarios.
How found
Found by a customer testing EF7 bits.
Regression
No, this is in the new feature.
Testing
New testing added for the reported scenario and additional cases around it.
Risk
Low, only affects JSON scenarios using non-standard query (e.g. FromSql). Fix applies exactly the same logic we use in the general scenario, as it is necessary but was missing.