Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better perf in SupportedMethods calculation in SqlServerConvertTransl… #34421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ public class SqlServerConvertTranslator : IMethodCallTranslator
typeof(object)
];

private static readonly MethodInfo[] SupportedMethods
= TypeMapping.Keys
.SelectMany(
t => typeof(Convert).GetTypeInfo().GetDeclaredMethods(t)
.Where(
m => m.GetParameters().Length == 1
&& SupportedTypes.Contains(m.GetParameters().First().ParameterType)))
.ToArray();
private static readonly MethodInfo[] SupportedMethods;

private readonly ISqlExpressionFactory _sqlExpressionFactory;

Expand All @@ -63,6 +56,22 @@ public SqlServerConvertTranslator(ISqlExpressionFactory sqlExpressionFactory)
_sqlExpressionFactory = sqlExpressionFactory;
}

static SqlServerConvertTranslator()
{
var convertInfo = typeof(Convert).GetTypeInfo();
SupportedMethods = TypeMapping.Keys
.SelectMany(
name => convertInfo.GetDeclaredMethods(name)
.Where(
method =>
{
var parameters = method.GetParameters();
return parameters.Length == 1
&& SupportedTypes.Contains(parameters[0].ParameterType);
}))
.ToArray();
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down