Repository navigation
Conversation
…ingBaseComparer When table-valued functions or stored procedures share the same name and schema but differ in parameter count or types, TableMappingBaseComparer previously compared them only by Table.Name and Table.Schema, causing them to compare as equal. When stored in a SortedSet (such as FunctionColumnMappings on IProperty), mappings for overloaded functions were dropped as duplicates, leading to NullReferenceException when translating queries. Fixes dotnet#33542
There was a problem hiding this comment.
🟢 Approval recommended
Only a minor test-coverage nit remains; no blocking issues were identified.
0 open findings
What changed in this PR
This PR fixes overloaded TVF and stored procedure mapping collisions by comparing parameter signatures.
Changes:
- Compare parameter count, store type, and name.
- Update hash computation consistently.
- Expand regression coverage for overloaded functions.
| File | Summary |
|---|---|
test/EFCore.Relational.Tests/Metadata/RelationalModelTest.cs |
Verifies overloaded function mappings and column lookup. |
src/EFCore.Relational/Metadata/Internal/TableMappingBaseComparer.cs |
Adds parameter-aware comparison and hashing. Nit: add coverage for overloads with different parameter counts. |
🧠 Review effort: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| return result; | ||
| } | ||
|
|
||
| if (x.Table is IStoreFunction xFunction) |
There was a problem hiding this comment.
Instead of casting here derive from IComparable in ITableMappingBase and IColumnMappingBase and implement them as appropriate.
There was a problem hiding this comment.
Updated in commit fdceb8e. Derived ITableMappingBase from IComparable and IColumnMappingBase from IComparable. Implemented CompareTo on ColumnMappingBase and TableMappingBase, and overridden in FunctionMapping and StoredProcedureMapping to compare parameter details. TableMappingBaseComparer and ColumnMappingBaseComparer now delegate cleanly to CompareTo without type casting.
fdceb8e to
4564281
Compare
Fixes #33542
Description
When table-valued functions (TVFs) or stored procedures share the same name and schema but differ in parameter count or parameter types (overloads),
TableMappingBaseComparerpreviously compared them only byTable.NameandTable.Schema. As a result, different store function mappings were treated as identical (Comparereturned0).Because
FunctionColumnMappingsonIPropertyusesSortedSet<FunctionColumnMapping>(which sorts viaColumnMappingBaseComparerand delegates toTableMappingBaseComparer), mappings for subsequent overloaded TVFs were dropped as duplicates. At query translation time,storeFunction.FindColumn(property)returnednullfor the omitted overload, causingNullReferenceExceptioninConcreteColumnExpression.This PR updates
TableMappingBaseComparer:IStoreFunctioninstances by parameter count, followed by parameterStoreTypeandName.IStoreStoredProcedureinstances by parameter count, followed by parameterStoreTypeandName.GetHashCodeto include function and stored procedure parameter attributes, keeping it consistent withEqualsandCompare.Testing
Can_use_relational_model_with_functionsinRelationalModelTestto assert that all 3 function column mappings are retained for overloaded functions.FindColumnreturns the mapped column for both overloaded functions.RelationalModelTesttests pass.