Make FromSql work on entity types containing complex JSON #37235
+170
−2
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.
Closes #34627
Description
One of EF 10.0's main new features is full support for complex JSON. Unfortunately, we had an omission where the necessary modeling information is absent for raw SQL queries. While the full, proper fix is tracked as #34627 for 11, this PR proposes to temporarily work around the lack of modeling information, allowing the use of SQL queries on entities which have JSON complex types.
Customer impact
Entity types which have complex JSON types on them cannot currently be queried out with SQL queries (e.g. FromSql), which is an important and often-used mechanism where EF cannot translate from LINQ (or translates to sub-optimal SQL).
How found
Multiple customers reported on 10.0.0
Regression
No.
Testing
Added.
Risk
Very low, trivial targeted fix for a case that otherwise immediately throws an exception.
Original description
@AndriySvyryd it's currently impossible to use FromSql on an entity type that contains a complex JSON column, because of #34627. While we should probably do #34627 properly for 11 (should we move it out of the backlog?), it seems possible to work around this in query for 10.0 - what do you think about the approach (temporary only)?
Note that view-only mapping still doesn't work since there's no mapping whatsoever (i.e. there must be a table mapping) - but that seems much more edge-casey.