Skip to content

Improve relational model integration in Query - #38346

Merged
AndriySvyryd merged 5 commits into
mainfrom
QueryModel
Jun 10, 2026
Merged

AndriySvyryd merged 5 commits into
mainfrom
QueryModel

Conversation

@AndriySvyryd

@AndriySvyryd AndriySvyryd commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #38060
Fixes #35466
Fixes #32853

The query pipeline previously fell back to model‑wide accessors (GetJsonPropertyName, container‑column‑by‑name scans) at translation time, which produced wrong/ambiguous results under entity splitting, TPT, and JSON‑on‑view scenarios. This change threads the actual table set and JSON element metadata through the existing relational query expressions and consolidates priority logic in one place.

Changes

  • New GetQueryMappings() internal helper (RelationalTypeBaseExtensions) returns storage mappings in priority order — default SQL query → default function → view → table — and replaces all GetViewOrTableMappings() call sites in the query pipeline. Casts directly to the concrete List<TMapping> runtime type and filters in place to avoid LINQ allocations.
  • StructuralTypeProjectionExpression.TableMap (optional IReadOnlyDictionary<ITableBase, string>) — threaded through TPT, single‑table, entity‑splitting and TPC CreateSelect branches, preserved across MakeNullable, UpdateEntityType, VisitChildren, set‑op merge, and subquery lift. BindProperty, TryRewriteEntityEquality, and GenerateMaterializationCondition now scope their principal‑split‑table lookup to the actually‑projected tables.
  • JsonQueryExpression.FindJsonElement(IPropertyBase) — returns the IRelationalJsonElement whose containing column matches JsonColumn when available, otherwise the first element from the property's mappings. BindProperty/BindStructuralProperty and the OPENJSON/json_each translators in RelationalQueryableMethodTranslatingExpressionVisitor, SqlServer, and Sqlite now use this instead of model‑wide GetJsonPropertyName().
  • JsonProjectionInfo.JsonColumn + ColumnExpression.Column preservation in MakeNullable/ApplyTypeMapping — the shaper now uses the column resolved at CreateSelect time, falling back to a model scan only when there's no underlying IColumnBase (synthetic JSON columns over OPENJSON/json_each).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 34 out of 35 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review June 2, 2026 06:54
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner June 2, 2026 06:54
Copilot AI review requested due to automatic review settings June 2, 2026 06:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 37 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported

Copilot AI review requested due to automatic review settings June 4, 2026 20:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported

Copilot AI review requested due to automatic review settings June 5, 2026 05:08
@AndriySvyryd
AndriySvyryd requested a review from cincuranet June 5, 2026 05:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings June 5, 2026 05:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported

@AndriySvyryd
AndriySvyryd merged commit 33d476d into main Jun 10, 2026
14 checks passed
@AndriySvyryd
AndriySvyryd deleted the QueryModel branch June 10, 2026 22:12
@github-actions github-actions Bot added the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

API review baseline changes for src/EFCore.Relational/EFCore.Relational.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  static class Microsoft.EntityFrameworkCore.Diagnostics.RelationalStrings
+ static string JsonElementMappingNotFound(object? structuralType, object? name, object? columnName);
+ static string JsonQueryExpressionWithoutUnderlyingColumn(object? structuralType);
  class Microsoft.EntityFrameworkCore.Query.JsonQueryExpression : System.Linq.Expressions.Expression, Microsoft.EntityFrameworkCore.Query.IPrintableExpression
+ virtual IRelationalJsonElement? FindJsonElement(IPropertyBase propertyBase);
+ virtual IRelationalJsonElement GetJsonElement(IPropertyBase propertyBase);

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 12, 2026
@AndriySvyryd AndriySvyryd removed the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants