Refactor method/member translators to stop using reflection lookup#37656
Merged
roji merged 1 commit intodotnet:mainfrom Feb 12, 2026
Merged
Refactor method/member translators to stop using reflection lookup#37656roji merged 1 commit intodotnet:mainfrom
roji merged 1 commit intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors multiple provider-specific method/member translators to avoid eager MethodInfo/MemberInfo reflection lookups (improving trimming compatibility and reducing startup reflection overhead), switching to name/declaring-type matching and argument-shape validation.
Changes:
- Replace static reflection-based
MethodInfo/MemberInfocaches withDeclaringType/Namechecks (often with list-pattern argument validation). - Convert many translators to primary-constructor style and remove backing
_sqlExpressionFactoryfields where possible. - Simplify/reshape some translation helpers (e.g., math/string translation dispatch via
switch).
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteSubstrMethodTranslator.cs | Stop caching MethodInfo; match Substr by declaring type/name and argument shape. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringMethodTranslator.cs | Replace many cached MethodInfo checks with switch on method name and argument patterns. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringLengthTranslator.cs | Member translation switches from reflection lookup to name/declaring-type checks. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringAggregateMethodTranslator.cs | Stop caching MethodInfo; select separator based on method name/arguments. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteRegexMethodTranslator.cs | Match Regex.IsMatch without cached MethodInfo. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteRandomTranslator.cs | Match DbFunctionsExtensions.Random without cached MethodInfo. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteQueryableAggregateMethodTranslator.cs | Primary-constructor refactor; use injected factory directly. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteObjectToStringTranslator.cs | Remove HashSet<Type> in favor of explicit supported-type checks. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteMathTranslator.cs | Replace static MethodInfo dictionary with method-name/type-based dispatch and helpers. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteHexMethodTranslator.cs | Stop caching MethodInfo; match Hex/Unhex by declaring type/name and args. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteGlobMethodTranslator.cs | Stop caching MethodInfo; match Glob by declaring type/name and args. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteDateTimeMethodTranslator.cs | Replace MethodInfo mapping dictionaries with method-name-based dispatch and shared modifier helper. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteDateOnlyMethodTranslator.cs | Minor pattern-match simplification for DateOnly.FromDateTime. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteCharMethodTranslator.cs | Replace supported-method dictionary with method-name-based dispatch. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteByteArrayMethodTranslator.cs | Replace EnumerableMethods.Contains MethodInfo match with declaring-type/name/args checks. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeOnlyMethodTranslator.cs | Stop caching MethodInfo; match TimeOnly methods via names/argument patterns. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerStringMethodTranslator.cs | Replace many cached MethodInfo checks with method-name/arg-shape dispatch; extract helpers. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerStringAggregateMethodTranslator.cs | Stop caching MethodInfo; select separator based on method name/arguments. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerNewGuidTranslator.cs | Match Guid.NewGuid without cached MethodInfo. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerMathTranslator.cs | Replace static mapping dictionaries with method-name/type-based dispatch and local helpers. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerIsNumericFunctionTranslator.cs | Stop caching MethodInfo; match IsNumeric by declaring type/name. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerIsDateFunctionTranslator.cs | Stop caching MethodInfo; match IsDate by declaring type/name. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerFullTextSearchFunctionsTranslator.cs | Replace reflection-based mapping with method-name dispatch for FreeText/Contains. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerFromPartsFunctionTranslator.cs | Replace reflection-based function mapping with method-name dispatch. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateTimeMethodTranslator.cs | Replace MethodInfo mapping dictionaries with method-name-based dispatch for DATEADD/Unix time conversions. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs | Replace reflection mappings with method-name-based dispatch and argument-pattern checks. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateDiffFunctionsTranslator.cs | Replace large MethodInfo mapping dictionary with method-name-based dispatch. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDataLengthFunctionTranslator.cs | Remove MethodInfo set and use declaring-type/name checks plus store-type pattern matching. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerConvertTranslator.cs | Remove static reflection initialization; validate Convert.ToX via name + parameter-type checks. |
| src/EFCore.SqlServer/Query/Internal/Translators/SqlServerByteArrayMethodTranslator.cs | Replace EnumerableMethods.* MethodInfo comparisons with declaring-type/name/args checks. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosStringMethodTranslator.cs | Remove many cached MethodInfo fields; dispatch via method-name/argument patterns. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosRegexTranslator.cs | Match Regex.IsMatch by declaring type/name and argument-count patterns. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosRandomTranslator.cs | Match DbFunctionsExtensions.Random by declaring type/name. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosMathTranslator.cs | Replace static MethodInfo dictionary with method-name/type-based dispatch. |
| src/EFCore.Cosmos/Query/Internal/Translators/CosmosDateTimeMethodTranslator.cs | Replace reflection-based date-part mapping with method-name dispatch (with declaring-type guard). |
src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringMethodTranslator.cs
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerByteArrayMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteByteArrayMethodTranslator.cs
Show resolved
Hide resolved
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
AndriySvyryd
approved these changes
Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #27113